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

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 by ncarter. 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 : contents_(web_contents),
24 current_request_id_(kInvalidId),
25 current_session_id_(kInvalidId),
26 number_of_matches_(0),
27 active_match_ordinal_(0) {}
28
29 FindRequestManager::~FindRequestManager() {}
30
31 void FindRequestManager::Find(int request_id,
32 const base::string16& search_text,
33 const blink::WebFindOptions& options) {
34 // Every find request must have a unique ID, and these IDs must strictly
35 // increase so that newer requests always have greater IDs than older
36 // requests.
37 DCHECK_GT(request_id, current_request_id_);
38 DCHECK_GT(request_id, current_session_id_);
39
40 current_request_id_ = request_id;
41 current_find_options_ = options;
42
43 if (!options.findNext)
44 Reset(request_id, search_text);
45
46 SendFindIPC(request_id, contents_->GetMainFrame());
47 }
48
49 void FindRequestManager::StopFinding(StopFindAction action) {
50 SendStopFindingIPC(action, contents_->GetMainFrame());
51 current_session_id_ = kInvalidId;
52 }
53
54 void FindRequestManager::OnFindReply(RenderFrameHost* rfh,
55 int request_id,
56 int number_of_matches,
57 const gfx::Rect& selection_rect,
58 int active_match_ordinal,
59 bool final_update) {
60 // Ignore stale replies from abandoned find sessions.
61 if (current_session_id_ == kInvalidId || request_id < current_session_id_)
62 return;
63
64 // Update the stored results.
65 number_of_matches_ = number_of_matches;
66 selection_rect_ = selection_rect;
67 active_match_ordinal_ = active_match_ordinal;
68
69 NotifyFindReply(request_id, final_update);
70 }
71
72 #if defined(OS_ANDROID)
73 void FindRequestManager::ActivateNearestFindResult(float x,
74 float y) {
75 if (current_session_id_ == kInvalidId)
76 return;
77
78 auto rfh = contents_->GetMainFrame();
79 rfh->Send(new InputMsg_ActivateNearestFindResult(
80 rfh->GetRoutingID(), current_session_id_, x, y));
81 }
82
83 void FindRequestManager::RequestFindMatchRects(int current_version) {
84 fmr_request_version_ = current_version;
85 SendFindMatchRectsIPC(contents_->GetMainFrame());
86 }
87
88 void FindRequestManager::FindMatchRectsReply(
89 RenderFrameHost* rfh,
90 int version,
91 const std::vector<gfx::RectF>& rects,
92 const gfx::RectF& active_rect) {
93 contents_->FindMatchRectsReply(version, rects, active_rect);
94 }
95 #endif
96
97 void FindRequestManager::Reset(int new_session_id,
98 const base::string16& new_search_text) {
99 current_session_id_ = new_session_id;
100 current_search_text_ = new_search_text;
101 number_of_matches_ = 0;
102 active_match_ordinal_ = 0;
103 selection_rect_ = gfx::Rect();
104 }
105
106 void FindRequestManager::SendFindIPC(int request_id, RenderFrameHost* rfh) {
107 rfh->Send(new FrameMsg_Find(rfh->GetRoutingID(), request_id,
108 current_search_text_, current_find_options_));
109 }
110
111 void FindRequestManager::SendStopFindingIPC(StopFindAction action,
112 RenderFrameHost* rfh) const {
113 rfh->Send(new FrameMsg_StopFinding(rfh->GetRoutingID(), action));
114 }
115
116 void FindRequestManager::NotifyFindReply(int request_id,
117 bool final_update) const {
118 if (request_id == kInvalidId) {
119 NOTREACHED();
120 return;
121 }
122
123 contents_->NotifyFindReply(request_id, number_of_matches_, selection_rect_,
124 active_match_ordinal_, final_update);
125 }
126
127 #if defined(OS_ANDROID)
128 void FindRequestManager::SendFindMatchRectsIPC(RenderFrameHost* rfh) {
129 rfh->Send(new FrameMsg_FindMatchRects(rfh->GetRoutingID(),
130 fmr_request_version_));
131 }
132 #endif
133
134 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698