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

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: Addressed comments and introduced FindRequest struct. 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 namespace {
15
16 // An invalid ID. This value is invalid for any render process ID, render frame
17 // ID, or find request ID.
18 const int kInvalidId = -1;
19
20 } // namespace
21
22 FindRequestManager::FindRequestManager(WebContentsImpl* web_contents)
23 :
24 #if defined(OS_ANDROID)
25 match_rects_{kInvalidId},
ncarter (slow) 2016/04/11 21:27:35 This is C++11 uniform initialization syntax, which
paulmeyer 2016/04/12 17:54:25 Done.
26 #endif
27 contents_(web_contents),
28 current_session_id_(kInvalidId),
29 current_request_(),
30 number_of_matches_(0),
31 active_match_ordinal_(0) {}
32
33 FindRequestManager::~FindRequestManager() {}
34
35 void FindRequestManager::Find(int request_id,
36 const base::string16& search_text,
37 const blink::WebFindOptions& options) {
38 // Every find request must have a unique ID, and these IDs must strictly
39 // increase so that newer requests always have greater IDs than older
40 // requests.
41 DCHECK_GT(request_id, current_request_.id);
42 DCHECK_GT(request_id, current_session_id_);
43
44 FindRequest request{request_id, search_text, options};
lfg 2016/04/11 20:10:53 Compared to what you had before, this will cause a
ncarter (slow) 2016/04/11 21:27:35 Use assignment syntax here, per the "BarStruct" dr
paulmeyer 2016/04/12 17:54:25 lfg: That won't be the case anymore after subseque
paulmeyer 2016/04/12 17:54:25 ncarter: Done.
45
46 if (options.findNext) {
47 // This is a find next operation.
48
49 // This implies that there is an ongoing find session with the same search
50 // text.
51 DCHECK_GE(current_session_id_, 0);
52 DCHECK_EQ(request.search_text, current_request_.search_text);
53 } else {
54 // This is an initial find operation.
55 Reset(request);
56 }
57
58 SendFindIPC(request, contents_->GetMainFrame());
59 }
60
61 void FindRequestManager::StopFinding(StopFindAction action) {
62 SendStopFindingIPC(action, contents_->GetMainFrame());
63 current_session_id_ = kInvalidId;
64 }
65
66 void FindRequestManager::OnFindReply(RenderFrameHost* rfh,
67 int request_id,
68 int number_of_matches,
69 const gfx::Rect& selection_rect,
70 int active_match_ordinal,
71 bool final_update) {
72 // Ignore stale replies from abandoned find sessions.
73 if (current_session_id_ == kInvalidId || request_id < current_session_id_)
74 return;
75
76 // Update the stored results.
77 number_of_matches_ = number_of_matches;
78 selection_rect_ = selection_rect;
79 active_match_ordinal_ = active_match_ordinal;
80
81 NotifyFindReply(request_id, final_update);
82 }
83
84 #if defined(OS_ANDROID)
85 void FindRequestManager::ActivateNearestFindResult(float x,
86 float y) {
87 if (current_session_id_ == kInvalidId)
88 return;
89
90 auto rfh = contents_->GetMainFrame();
91 rfh->Send(new InputMsg_ActivateNearestFindResult(
92 rfh->GetRoutingID(), current_session_id_, x, y));
93 }
94
95 void FindRequestManager::RequestFindMatchRects(int current_version) {
96 match_rects_.request_version = current_version;
97 SendFindMatchRectsIPC(contents_->GetMainFrame());
98 }
99
100 void FindRequestManager::OnFindMatchRectsReply(
101 RenderFrameHost* rfh,
102 int version,
103 const std::vector<gfx::RectF>& rects,
104 const gfx::RectF& active_rect) {
105 contents_->NotifyFindMatchRectsReply(version, rects, active_rect);
106 }
107 #endif
108
109 void FindRequestManager::Reset(const FindRequest& initial_request) {
110 current_session_id_ = initial_request.id;
111 current_request_ = initial_request;
112 number_of_matches_ = 0;
113 active_match_ordinal_ = 0;
114 selection_rect_ = gfx::Rect();
115 #if defined(OS_ANDROID)
116 match_rects_ = FindMatchRectsState();
ncarter (slow) 2016/04/11 21:27:35 The default ctor isn't declared, so as far as I ca
lfg 2016/04/11 21:46:42 We had this discussion offline (I also didn't know
paulmeyer 2016/04/12 17:54:25 I made the construction explicit now.
ncarter (slow) 2016/04/12 18:16:35 Thanks for explaining this (the zero initializatio
117 #endif
118 }
119
120 void FindRequestManager::SendFindIPC(FindRequest request,
lfg 2016/04/11 20:10:53 Pass by const reference.
paulmeyer 2016/04/12 17:54:25 Done.
121 RenderFrameHost* rfh) {
122 rfh->Send(new FrameMsg_Find(rfh->GetRoutingID(), request.id,
123 request.search_text, request.options));
124 }
125
126 void FindRequestManager::SendStopFindingIPC(StopFindAction action,
127 RenderFrameHost* rfh) const {
128 rfh->Send(new FrameMsg_StopFinding(rfh->GetRoutingID(), action));
129 }
130
131 void FindRequestManager::NotifyFindReply(int request_id,
132 bool final_update) const {
133 if (request_id == kInvalidId) {
134 NOTREACHED();
135 return;
136 }
137
138 contents_->NotifyFindReply(request_id, number_of_matches_, selection_rect_,
139 active_match_ordinal_, final_update);
140 }
141
142 #if defined(OS_ANDROID)
143 void FindRequestManager::SendFindMatchRectsIPC(RenderFrameHost* rfh) {
144 rfh->Send(new FrameMsg_FindMatchRects(rfh->GetRoutingID(),
145 match_rects_.request_version));
146 }
147 #endif
148
149 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698