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

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

Issue 1851793002: Implement a shell of FindRequestManager, and hook it up to WebContentsImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased and small fix. Created 4 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/find_request_manager.h"
6
7 #include "content/browser/frame_host/render_frame_host_impl.h"
8 #include "content/browser/web_contents/web_contents_impl.h"
9 #include "content/common/frame_messages.h"
10 #include "content/common/input_messages.h"
11
12 namespace content {
13
14 // static
15 const int FindRequestManager::kInvalidId = -1;
16
17 FindRequestManager::FindRequestManager(WebContentsImpl* web_contents)
18 : contents_(web_contents),
19 current_session_id_(kInvalidId),
20 number_of_matches_(0),
21 active_match_ordinal_(0) {}
22
23 FindRequestManager::~FindRequestManager() {}
24
25 void FindRequestManager::Find(int request_id,
26 const base::string16& search_text,
27 const blink::WebFindOptions& options) {
28 // Every find request must have a unique ID, and these IDs must strictly
29 // increase so that newer requests always have greater IDs than older
30 // requests.
31 DCHECK_GT(request_id, current_request_.id);
32 DCHECK_GT(request_id, current_session_id_);
33
34 FindRequest request(request_id, search_text, options);
35
36 if (options.findNext) {
37 // This is a find next operation.
38
39 // This implies that there is an ongoing find session with the same search
40 // text.
41 DCHECK_GE(current_session_id_, 0);
42 DCHECK_EQ(request.search_text, current_request_.search_text);
43 } else {
44 // This is an initial find operation.
45 Reset(request);
46 }
47
48 SendFindIPC(request, contents_->GetMainFrame());
49 }
50
51 void FindRequestManager::StopFinding(StopFindAction action) {
52 SendStopFindingIPC(action, contents_->GetMainFrame());
53 current_session_id_ = kInvalidId;
54 }
55
56 void FindRequestManager::OnFindReply(RenderFrameHost* rfh,
57 int request_id,
58 int number_of_matches,
59 const gfx::Rect& selection_rect,
60 int active_match_ordinal,
61 bool final_update) {
62 // Ignore stale replies from abandoned find sessions.
63 if (current_session_id_ == kInvalidId || request_id < current_session_id_)
64 return;
65
66 // Update the stored results.
67 number_of_matches_ = number_of_matches;
68 selection_rect_ = selection_rect;
69 active_match_ordinal_ = active_match_ordinal;
70
71 NotifyFindReply(request_id, final_update);
72 }
73
74 #if defined(OS_ANDROID)
75 void FindRequestManager::ActivateNearestFindResult(float x,
76 float y) {
77 if (current_session_id_ == kInvalidId)
78 return;
79
80 auto rfh = contents_->GetMainFrame();
81 rfh->Send(new InputMsg_ActivateNearestFindResult(
82 rfh->GetRoutingID(), current_session_id_, x, y));
83 }
84
85 void FindRequestManager::RequestFindMatchRects(int current_version) {
86 match_rects_.request_version = current_version;
87 SendFindMatchRectsIPC(contents_->GetMainFrame());
88 }
89
90 void FindRequestManager::OnFindMatchRectsReply(
91 RenderFrameHost* rfh,
92 int version,
93 const std::vector<gfx::RectF>& rects,
94 const gfx::RectF& active_rect) {
95 contents_->NotifyFindMatchRectsReply(version, rects, active_rect);
96 }
97 #endif
98
99 void FindRequestManager::Reset(const FindRequest& initial_request) {
100 current_session_id_ = initial_request.id;
101 current_request_ = initial_request;
102 number_of_matches_ = 0;
103 active_match_ordinal_ = 0;
104 selection_rect_ = gfx::Rect();
105 #if defined(OS_ANDROID)
106 match_rects_ = FindMatchRectsState();
107 #endif
108 }
109
110 void FindRequestManager::SendFindIPC(const FindRequest& request,
111 RenderFrameHost* rfh) {
112 rfh->Send(new FrameMsg_Find(rfh->GetRoutingID(), request.id,
113 request.search_text, request.options));
114 }
115
116 void FindRequestManager::SendStopFindingIPC(StopFindAction action,
117 RenderFrameHost* rfh) const {
118 rfh->Send(new FrameMsg_StopFinding(rfh->GetRoutingID(), action));
119 }
120
121 void FindRequestManager::NotifyFindReply(int request_id,
122 bool final_update) const {
123 if (request_id == kInvalidId) {
124 NOTREACHED();
125 return;
126 }
127
128 contents_->NotifyFindReply(request_id, number_of_matches_, selection_rect_,
129 active_match_ordinal_, final_update);
130 }
131
132 #if defined(OS_ANDROID)
133 void FindRequestManager::SendFindMatchRectsIPC(RenderFrameHost* rfh) {
134 rfh->Send(new FrameMsg_FindMatchRects(rfh->GetRoutingID(),
135 match_rects_.request_version));
136 }
137 #endif
138
139 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/find_request_manager.h ('k') | content/browser/frame_host/render_frame_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698