blob: b3ba09ded99ba3822f0a634d3e1caae9ce47cc7d [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2018 The Chromium Authors
Rakina Zata Amni724f3efe2018-07-23 03:19:462// 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 Prada43da8572019-07-17 21:13:017#include <utility>
8
Rakina Zata Amni724f3efe2018-07-23 03:19:469#include "content/browser/find_request_manager.h"
danakje94b7c842020-09-16 18:47:4310#include "content/browser/renderer_host/render_frame_host_impl.h"
Mario Sanchez Prada43da8572019-07-17 21:13:0111#include "mojo/public/cpp/bindings/pending_remote.h"
Rakina Zata Amni724f3efe2018-07-23 03:19:4612
13namespace content {
14
15FindInPageClient::FindInPageClient(FindRequestManager* find_request_manager,
16 RenderFrameHostImpl* rfh)
Mario Sanchez Prada43da8572019-07-17 21:13:0117 : frame_(rfh), find_request_manager_(find_request_manager) {
18 frame_->GetFindInPage()->SetClient(receiver_.BindNewPipeAndPassRemote());
Rakina Zata Amni724f3efe2018-07-23 03:19:4619}
20
21FindInPageClient::~FindInPageClient() {}
22
23void FindInPageClient::SetNumberOfMatches(
24 int request_id,
25 unsigned int number_of_matches,
26 blink::mojom::FindMatchUpdateType update_type) {
Rakina Zata Amni2ac57502018-08-16 01:44:4527 if (find_request_manager_->ShouldIgnoreReply(frame_, request_id))
28 return;
Rakina Zata Amni724f3efe2018-07-23 03:19:4629 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 Amni2ac57502018-08-16 01:44:4533 HandleUpdateType(request_id, update_type);
34}
35
36void 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 Zhang25979e22022-07-07 21:58:3149#if BUILDFLAG(IS_ANDROID)
Rakina Zata Amni2ac57502018-08-16 01:44:4550void FindInPageClient::ActivateNearestFindResult(int request_id,
51 const gfx::PointF& point) {
52 frame_->GetFindInPage()->ActivateNearestFindResult(request_id, point);
53}
Lei Zhang25979e22022-07-07 21:58:3154#endif
Rakina Zata Amni2ac57502018-08-16 01:44:4555
56void FindInPageClient::HandleUpdateType(
57 int request_id,
58 blink::mojom::FindMatchUpdateType update_type) {
Rakina Zata Amni724f3efe2018-07-23 03:19:4659 // 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 Amni724f3efe2018-07-23 03:19:4670} // namespace content