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

Side by Side Diff: content/browser/find_request_manager.cc

Issue 2723253002: Fix beep when navigating/closing a page with find bar open
Patch Set: android Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/find_request_manager.h" 5 #include "content/browser/find_request_manager.h"
6 6
7 #include "content/browser/frame_host/render_frame_host_impl.h" 7 #include "content/browser/frame_host/render_frame_host_impl.h"
8 #include "content/browser/web_contents/web_contents_impl.h" 8 #include "content/browser/web_contents/web_contents_impl.h"
9 #include "content/common/frame_messages.h" 9 #include "content/common/frame_messages.h"
10 #include "content/common/input_messages.h" 10 #include "content/common/input_messages.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 active_frame_ = rfh; 186 active_frame_ = rfh;
187 relative_active_match_ordinal_ = active_match_ordinal; 187 relative_active_match_ordinal_ = active_match_ordinal;
188 UpdateActiveMatchOrdinal(); 188 UpdateActiveMatchOrdinal();
189 } 189 }
190 if (pending_active_match_ordinal_ && request_id == current_request_.id) 190 if (pending_active_match_ordinal_ && request_id == current_request_.id)
191 pending_active_match_ordinal_ = false; 191 pending_active_match_ordinal_ = false;
192 AdvanceQueue(request_id); 192 AdvanceQueue(request_id);
193 } 193 }
194 194
195 if (!final_update) { 195 if (!final_update) {
196 NotifyFindReply(request_id, false /* final_update */); 196 NotifyFindReply(request_id, false /* final_update */,
197 false /* was_frame_removal */);
197 return; 198 return;
198 } 199 }
199 200
200 // This is the final update for this frame for the current find operation. 201 // This is the final update for this frame for the current find operation.
201 202
202 pending_initial_replies_.erase(rfh); 203 pending_initial_replies_.erase(rfh);
203 if (request_id == current_session_id_ && !pending_initial_replies_.empty()) { 204 if (request_id == current_session_id_ && !pending_initial_replies_.empty()) {
204 NotifyFindReply(request_id, false /* final_update */); 205 NotifyFindReply(request_id, false /* final_update */,
206 false /* was_frame_removal */);
205 return; 207 return;
206 } 208 }
207 209
208 // This is the final update for the current find operation. 210 // This is the final update for the current find operation.
209 211
210 if (request_id == current_request_.id && request_id != current_session_id_) { 212 if (request_id == current_request_.id && request_id != current_session_id_) {
211 DCHECK(current_request_.options.findNext); 213 DCHECK(current_request_.options.findNext);
212 DCHECK_EQ(pending_find_next_reply_, rfh); 214 DCHECK_EQ(pending_find_next_reply_, rfh);
213 pending_find_next_reply_ = nullptr; 215 pending_find_next_reply_ = nullptr;
214 } 216 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // A reply should not be expected from the removed frame. 254 // A reply should not be expected from the removed frame.
253 RemoveNearestFindResultPendingReply(rfh); 255 RemoveNearestFindResultPendingReply(rfh);
254 RemoveFindMatchRectsPendingReply(rfh); 256 RemoveFindMatchRectsPendingReply(rfh);
255 #endif 257 #endif
256 258
257 // If no pending find replies are expected for the removed frame, then just 259 // If no pending find replies are expected for the removed frame, then just
258 // report the updated results. 260 // report the updated results.
259 if (!pending_initial_replies_.count(rfh) && pending_find_next_reply_ != rfh) { 261 if (!pending_initial_replies_.count(rfh) && pending_find_next_reply_ != rfh) {
260 bool final_update = 262 bool final_update =
261 pending_initial_replies_.empty() && !pending_find_next_reply_; 263 pending_initial_replies_.empty() && !pending_find_next_reply_;
262 NotifyFindReply(current_session_id_, final_update); 264 NotifyFindReply(current_session_id_, final_update,
265 true /* was_frame_removal */);
263 return; 266 return;
264 } 267 }
265 268
266 if (pending_initial_replies_.count(rfh)) { 269 if (pending_initial_replies_.count(rfh)) {
267 // A reply should not be expected from the removed frame. 270 // A reply should not be expected from the removed frame.
268 pending_initial_replies_.erase(rfh); 271 pending_initial_replies_.erase(rfh);
269 if (pending_initial_replies_.empty()) { 272 if (pending_initial_replies_.empty()) {
270 FinalUpdateReceived(current_session_id_, rfh); 273 FinalUpdateReceived(current_session_id_, rfh);
271 } 274 }
272 } 275 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 445
443 if (request.options.findNext) 446 if (request.options.findNext)
444 pending_find_next_reply_ = rfh; 447 pending_find_next_reply_ = rfh;
445 else 448 else
446 pending_initial_replies_.insert(rfh); 449 pending_initial_replies_.insert(rfh);
447 450
448 rfh->Send(new FrameMsg_Find(rfh->GetRoutingID(), request.id, 451 rfh->Send(new FrameMsg_Find(rfh->GetRoutingID(), request.id,
449 request.search_text, request.options)); 452 request.search_text, request.options));
450 } 453 }
451 454
452 void FindRequestManager::NotifyFindReply(int request_id, bool final_update) { 455 void FindRequestManager::NotifyFindReply(int request_id,
456 bool final_update,
457 bool was_frame_removal) {
453 if (request_id == kInvalidId) { 458 if (request_id == kInvalidId) {
454 NOTREACHED(); 459 NOTREACHED();
455 return; 460 return;
456 } 461 }
457 462
458 // Ensure that replies are not reported with IDs lower than the ID of the 463 // Ensure that replies are not reported with IDs lower than the ID of the
459 // latest request we have results from. 464 // latest request we have results from.
460 if (request_id < last_reported_id_) 465 if (request_id < last_reported_id_)
461 request_id = last_reported_id_; 466 request_id = last_reported_id_;
462 else 467 else
463 last_reported_id_ = request_id; 468 last_reported_id_ = request_id;
464 469
465 contents_->NotifyFindReply(request_id, number_of_matches_, selection_rect_, 470 contents_->NotifyFindReply(request_id, number_of_matches_, selection_rect_,
466 active_match_ordinal_, final_update); 471 active_match_ordinal_, final_update,
472 was_frame_removal);
467 } 473 }
468 474
469 RenderFrameHost* FindRequestManager::GetInitialFrame(bool forward) const { 475 RenderFrameHost* FindRequestManager::GetInitialFrame(bool forward) const {
470 RenderFrameHost* rfh = contents_->GetMainFrame(); 476 RenderFrameHost* rfh = contents_->GetMainFrame();
471 477
472 if (!forward) 478 if (!forward)
473 rfh = GetDeepestLastChild(rfh); 479 rfh = GetDeepestLastChild(rfh);
474 480
475 return rfh; 481 return rfh;
476 } 482 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 549
544 void FindRequestManager::FinalUpdateReceived(int request_id, 550 void FindRequestManager::FinalUpdateReceived(int request_id,
545 RenderFrameHost* rfh) { 551 RenderFrameHost* rfh) {
546 if (!number_of_matches_ || 552 if (!number_of_matches_ ||
547 (active_match_ordinal_ && !pending_active_match_ordinal_) || 553 (active_match_ordinal_ && !pending_active_match_ordinal_) ||
548 pending_find_next_reply_) { 554 pending_find_next_reply_) {
549 // All the find results for |request_id| are in and ready to report. Note 555 // All the find results for |request_id| are in and ready to report. Note
550 // that |final_update| will be set to false if there are still pending 556 // that |final_update| will be set to false if there are still pending
551 // replies expected from the initial find request. 557 // replies expected from the initial find request.
552 NotifyFindReply(request_id, 558 NotifyFindReply(request_id,
553 pending_initial_replies_.empty() /* final_update */); 559 pending_initial_replies_.empty() /* final_update */,
560 false /* was_frame_removal */);
554 AdvanceQueue(request_id); 561 AdvanceQueue(request_id);
555 return; 562 return;
556 } 563 }
557 564
558 // There are matches, but no active match was returned, so another find next 565 // There are matches, but no active match was returned, so another find next
559 // request must be sent. 566 // request must be sent.
560 567
561 RenderFrameHost* target_rfh; 568 RenderFrameHost* target_rfh;
562 if (request_id == current_request_.id && current_request_.options.findNext) { 569 if (request_id == current_request_.id && current_request_.options.findNext) {
563 // If this was a find next operation, then the active match will be in the 570 // If this was a find next operation, then the active match will be in the
(...skipping 16 matching lines...) Expand all
580 target_rfh = Traverse(target_rfh, 587 target_rfh = Traverse(target_rfh,
581 current_request_.options.forward, 588 current_request_.options.forward,
582 true /* matches_only */, 589 true /* matches_only */,
583 false /* wrap */); 590 false /* wrap */);
584 } 591 }
585 } 592 }
586 DCHECK(target_rfh); 593 DCHECK(target_rfh);
587 594
588 // Forward the find reply without |final_update| set because the active match 595 // Forward the find reply without |final_update| set because the active match
589 // has not yet been found. 596 // has not yet been found.
590 NotifyFindReply(request_id, false /* final_update */); 597 NotifyFindReply(request_id, false /* final_update */,
598 false /* was_frame_removal */);
591 599
592 current_request_.options.findNext = true; 600 current_request_.options.findNext = true;
593 SendFindIPC(current_request_, target_rfh); 601 SendFindIPC(current_request_, target_rfh);
594 } 602 }
595 603
596 #if defined(OS_ANDROID) 604 #if defined(OS_ANDROID)
597 void FindRequestManager::RemoveNearestFindResultPendingReply( 605 void FindRequestManager::RemoveNearestFindResultPendingReply(
598 RenderFrameHost* rfh) { 606 RenderFrameHost* rfh) {
599 auto it = activate_.pending_replies.find(rfh); 607 auto it = activate_.pending_replies.find(rfh);
600 if (it == activate_.pending_replies.end()) 608 if (it == activate_.pending_replies.end())
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 aggregate_rects.end(), frame_rects.begin(), frame_rects.end()); 644 aggregate_rects.end(), frame_rects.begin(), frame_rects.end());
637 } 645 }
638 } 646 }
639 contents_->NotifyFindMatchRectsReply( 647 contents_->NotifyFindMatchRectsReply(
640 match_rects_.known_version, aggregate_rects, match_rects_.active_rect); 648 match_rects_.known_version, aggregate_rects, match_rects_.active_rect);
641 } 649 }
642 } 650 }
643 #endif 651 #endif
644 652
645 } // namespace content 653 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/find_request_manager.h ('k') | content/browser/find_request_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698