Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2018 The Chromium Authors |
Rakina Zata Amni | 724f3efe | 2018-07-23 03:19:46 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "content/browser/find_in_page_client.h" |
| 6 | |
Mario Sanchez Prada | 43da857 | 2019-07-17 21:13:01 | [diff] [blame] | 7 | #include <utility> |
| 8 | |
Rakina Zata Amni | 724f3efe | 2018-07-23 03:19:46 | [diff] [blame] | 9 | #include "content/browser/find_request_manager.h" |
danakj | e94b7c84 | 2020-09-16 18:47:43 | [diff] [blame] | 10 | #include "content/browser/renderer_host/render_frame_host_impl.h" |
Mario Sanchez Prada | 43da857 | 2019-07-17 21:13:01 | [diff] [blame] | 11 | #include "mojo/public/cpp/bindings/pending_remote.h" |
Rakina Zata Amni | 724f3efe | 2018-07-23 03:19:46 | [diff] [blame] | 12 | |
| 13 | namespace content { |
| 14 | |
| 15 | FindInPageClient::FindInPageClient(FindRequestManager* find_request_manager, |
| 16 | RenderFrameHostImpl* rfh) |
Mario Sanchez Prada | 43da857 | 2019-07-17 21:13:01 | [diff] [blame] | 17 | : frame_(rfh), find_request_manager_(find_request_manager) { |
| 18 | frame_->GetFindInPage()->SetClient(receiver_.BindNewPipeAndPassRemote()); |
Rakina Zata Amni | 724f3efe | 2018-07-23 03:19:46 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | FindInPageClient::~FindInPageClient() {} |
| 22 | |
| 23 | void FindInPageClient::SetNumberOfMatches( |
| 24 | int request_id, |
| 25 | unsigned int number_of_matches, |
| 26 | blink::mojom::FindMatchUpdateType update_type) { |
Rakina Zata Amni | 2ac5750 | 2018-08-16 01:44:45 | [diff] [blame] | 27 | if (find_request_manager_->ShouldIgnoreReply(frame_, request_id)) |
| 28 | return; |
Rakina Zata Amni | 724f3efe | 2018-07-23 03:19:46 | [diff] [blame] | 29 | const int old_matches = number_of_matches_; |
| 30 | number_of_matches_ = number_of_matches; |
| 31 | find_request_manager_->UpdatedFrameNumberOfMatches(frame_, old_matches, |
| 32 | number_of_matches); |
Rakina Zata Amni | 2ac5750 | 2018-08-16 01:44:45 | [diff] [blame] | 33 | HandleUpdateType(request_id, update_type); |
| 34 | } |
| 35 | |
| 36 | void FindInPageClient::SetActiveMatch( |
| 37 | int request_id, |
| 38 | const gfx::Rect& active_match_rect, |
| 39 | int active_match_ordinal, |
| 40 | blink::mojom::FindMatchUpdateType update_type) { |
| 41 | if (find_request_manager_->ShouldIgnoreReply(frame_, request_id)) |
| 42 | return; |
| 43 | find_request_manager_->SetActiveMatchRect(active_match_rect); |
| 44 | find_request_manager_->SetActiveMatchOrdinal(frame_, request_id, |
| 45 | active_match_ordinal); |
| 46 | HandleUpdateType(request_id, update_type); |
| 47 | } |
| 48 | |
Lei Zhang | 25979e2 | 2022-07-07 21:58:31 | [diff] [blame] | 49 | #if BUILDFLAG(IS_ANDROID) |
Rakina Zata Amni | 2ac5750 | 2018-08-16 01:44:45 | [diff] [blame] | 50 | void FindInPageClient::ActivateNearestFindResult(int request_id, |
| 51 | const gfx::PointF& point) { |
| 52 | frame_->GetFindInPage()->ActivateNearestFindResult(request_id, point); |
| 53 | } |
Lei Zhang | 25979e2 | 2022-07-07 21:58:31 | [diff] [blame] | 54 | #endif |
Rakina Zata Amni | 2ac5750 | 2018-08-16 01:44:45 | [diff] [blame] | 55 | |
| 56 | void FindInPageClient::HandleUpdateType( |
| 57 | int request_id, |
| 58 | blink::mojom::FindMatchUpdateType update_type) { |
Rakina Zata Amni | 724f3efe | 2018-07-23 03:19:46 | [diff] [blame] | 59 | // If this is the final update for this frame, it might be the final update |
| 60 | // for the find request out of all the frames, so we need to handle it. |
| 61 | // Otherwise just notify directly while saying this is not the final update |
| 62 | // for the request. |
| 63 | if (update_type == blink::mojom::FindMatchUpdateType::kFinalUpdate) |
| 64 | find_request_manager_->HandleFinalUpdateForFrame(frame_, request_id); |
| 65 | else |
| 66 | find_request_manager_->NotifyFindReply(request_id, |
| 67 | false /* final_update */); |
| 68 | } |
| 69 | |
Rakina Zata Amni | 724f3efe | 2018-07-23 03:19:46 | [diff] [blame] | 70 | } // namespace content |