1 // Copyright 2018 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CONTENT_BROWSER_FIND_IN_PAGE_CLIENT_H_
6 #define CONTENT_BROWSER_FIND_IN_PAGE_CLIENT_H_
7 
8 #include "mojo/public/cpp/bindings/receiver.h"
9 #include "third_party/blink/public/mojom/frame/find_in_page.mojom.h"
10 
11 namespace content {
12 
13 class RenderFrameHostImpl;
14 class FindRequestManager;
15 
16 // Per-frame client of FindInPage, owned by FindRequestManager.
17 // Keeps track of the current match count for the frame.
18 class FindInPageClient final : public blink::mojom::FindInPageClient {
19  public:
20   FindInPageClient(FindRequestManager* find_request_manager,
21                    RenderFrameHostImpl* rfh);
22 
23   ~FindInPageClient() override;
24 
25   void ActivateNearestFindResult(int request_id, const gfx::PointF& point);
26 
27   // Current number of matches for this frame.
number_of_matches()28   int number_of_matches() { return number_of_matches_; }
29 
30   // blink::mojom::FindInPageClient overrides
31 
32   void SetNumberOfMatches(int request_id,
33                           unsigned int current_number_of_matches,
34                           blink::mojom::FindMatchUpdateType update_type) final;
35 
36   void SetActiveMatch(int request_id,
37                       const gfx::Rect& active_match_rect,
38                       int active_match_ordinal,
39                       blink::mojom::FindMatchUpdateType update_type) final;
40 
41  private:
42   void HandleUpdateType(int request_id,
43                         blink::mojom::FindMatchUpdateType update_type);
44   RenderFrameHostImpl* const frame_;
45   FindRequestManager* const find_request_manager_;
46   mojo::Receiver<blink::mojom::FindInPageClient> receiver_{this};
47   int number_of_matches_ = 0;
48 
49   DISALLOW_COPY_AND_ASSIGN(FindInPageClient);
50 };
51 
52 }  // namespace content
53 
54 #endif  // CONTENT_BROWSER_FIND_IN_PAGE_CLIENT_H_
55