OLD | NEW |
---|---|
(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_session_id_(kInvalidId), | |
25 number_of_matches_(0), | |
26 active_match_ordinal_(0) {} | |
27 | |
28 FindRequestManager::~FindRequestManager() {} | |
29 | |
30 void FindRequestManager::Find(int request_id, | |
ncarter (slow)
2016/04/06 19:08:03
if request_id is comparable to current_session_id,
paulmeyer
2016/04/07 17:36:14
Yeah, they can be a bit confusing. Ironically, |cu
ncarter (slow)
2016/04/07 18:19:14
Oh, everything makes a lot more sense knowing this
| |
31 const base::string16& search_text, | |
32 const blink::WebFindOptions& options) { | |
33 DCHECK(request_id > current_session_id_); | |
ncarter (slow)
2016/04/06 19:08:03
DCHECK_GT.
Also could you add a comment (or << "l
paulmeyer
2016/04/07 17:36:14
Done.
| |
34 current_find_options_ = options; | |
35 | |
36 if (!options.findNext) | |
37 Reset(request_id, search_text); | |
38 | |
39 SendFindIPC(request_id, contents_->GetMainFrame()); | |
40 } | |
41 | |
42 void FindRequestManager::StopFinding(StopFindAction action) { | |
43 SendStopFindingIPC(action, contents_->GetMainFrame()); | |
44 current_session_id_ = kInvalidId; | |
45 } | |
46 | |
47 void FindRequestManager::FindReply(RenderFrameHost* rfh, | |
48 int request_id, | |
49 int number_of_matches, | |
50 const gfx::Rect& selection_rect, | |
51 int active_match_ordinal, | |
52 bool final_update) { | |
53 // Ignore stale replies from abandoned find sessions. | |
54 if (current_session_id_ == kInvalidId || request_id < current_session_id_) | |
55 return; | |
56 | |
57 // Update the stored results. | |
58 number_of_matches_ = number_of_matches; | |
59 selection_rect_ = selection_rect; | |
60 active_match_ordinal_ = active_match_ordinal; | |
61 | |
62 SendFindReply(request_id, final_update); | |
63 } | |
64 | |
65 #if defined(OS_ANDROID) | |
66 void FindRequestManager::ActivateNearestFindResult(float x, | |
67 float y) { | |
68 if (current_session_id_ == kInvalidId) | |
69 return; | |
70 | |
71 auto rfh = contents_->GetMainFrame(); | |
72 rfh->Send(new InputMsg_ActivateNearestFindResult( | |
73 rfh->GetRoutingID(), current_session_id_, x, y)); | |
74 } | |
75 | |
76 void FindRequestManager::RequestFindMatchRects(int current_version) { | |
77 fmr_request_version_ = current_version; | |
78 SendFindMatchRectsIPC(contents_->GetMainFrame()); | |
79 } | |
80 | |
81 void FindRequestManager::FindMatchRectsReply( | |
82 RenderFrameHost* rfh, | |
83 int version, | |
84 const std::vector<gfx::RectF>& rects, | |
85 const gfx::RectF& active_rect) { | |
86 contents_->FindMatchRectsReply(version, rects, active_rect); | |
87 } | |
88 #endif | |
89 | |
90 void FindRequestManager::Reset(int new_session_id, | |
91 const base::string16& new_search_text) { | |
92 current_session_id_ = new_session_id; | |
93 current_search_text_ = new_search_text; | |
94 number_of_matches_ = 0; | |
95 active_match_ordinal_ = 0; | |
96 selection_rect_ = gfx::Rect(); | |
97 } | |
98 | |
99 void FindRequestManager::SendFindIPC(int request_id, RenderFrameHost* rfh) { | |
100 rfh->Send(new FrameMsg_Find(rfh->GetRoutingID(), request_id, | |
101 current_search_text_, current_find_options_)); | |
102 } | |
103 | |
104 void FindRequestManager::SendStopFindingIPC(StopFindAction action, | |
105 RenderFrameHost* rfh) const { | |
106 rfh->Send(new FrameMsg_StopFinding(rfh->GetRoutingID(), action)); | |
107 } | |
108 | |
109 void FindRequestManager::SendFindReply(int request_id, | |
ncarter (slow)
2016/04/06 19:08:03
I propose we rename both FindRequestManager::SendF
paulmeyer
2016/04/07 17:36:14
You're right, "Send" doesn't fit. "Notify" seems m
| |
110 bool final_update) const { | |
111 if (request_id == kInvalidId) { | |
112 NOTREACHED(); | |
113 return; | |
114 } | |
115 | |
116 contents_->FindReply(request_id, number_of_matches_, selection_rect_, | |
117 active_match_ordinal_, final_update); | |
118 } | |
119 | |
120 #if defined(OS_ANDROID) | |
121 void FindRequestManager::SendFindMatchRectsIPC(RenderFrameHost* rfh) { | |
122 rfh->Send(new FrameMsg_FindMatchRects(rfh->GetRoutingID(), | |
123 fmr_request_version_)); | |
124 } | |
125 #endif | |
126 | |
127 } // namespace content | |
OLD | NEW |