Index: content/browser/find_request_manager.cc |
diff --git a/content/browser/find_request_manager.cc b/content/browser/find_request_manager.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..946945d8931097040c234bd778e8494f50d94241 |
--- /dev/null |
+++ b/content/browser/find_request_manager.cc |
@@ -0,0 +1,127 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/find_request_manager.h" |
+ |
+#include "content/browser/frame_host/render_frame_host_impl.h" |
+#include "content/browser/web_contents/web_contents_impl.h" |
+#include "content/common/frame_messages.h" |
+#include "content/common/input_messages.h" |
+ |
+namespace content { |
+ |
+namespace { |
+ |
+// An invalid ID. This value is invalid for any render process ID, render frame |
+// ID, or find request ID. |
+const int kInvalidId = -1; |
+ |
+} // namespace |
+ |
+FindRequestManager::FindRequestManager(WebContentsImpl* web_contents) |
+ : contents_(web_contents), |
+ current_session_id_(kInvalidId), |
+ number_of_matches_(0), |
+ active_match_ordinal_(0) {} |
+ |
+FindRequestManager::~FindRequestManager() {} |
+ |
+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
|
+ const base::string16& search_text, |
+ const blink::WebFindOptions& options) { |
+ 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.
|
+ current_find_options_ = options; |
+ |
+ if (!options.findNext) |
+ Reset(request_id, search_text); |
+ |
+ SendFindIPC(request_id, contents_->GetMainFrame()); |
+} |
+ |
+void FindRequestManager::StopFinding(StopFindAction action) { |
+ SendStopFindingIPC(action, contents_->GetMainFrame()); |
+ current_session_id_ = kInvalidId; |
+} |
+ |
+void FindRequestManager::FindReply(RenderFrameHost* rfh, |
+ int request_id, |
+ int number_of_matches, |
+ const gfx::Rect& selection_rect, |
+ int active_match_ordinal, |
+ bool final_update) { |
+ // Ignore stale replies from abandoned find sessions. |
+ if (current_session_id_ == kInvalidId || request_id < current_session_id_) |
+ return; |
+ |
+ // Update the stored results. |
+ number_of_matches_ = number_of_matches; |
+ selection_rect_ = selection_rect; |
+ active_match_ordinal_ = active_match_ordinal; |
+ |
+ SendFindReply(request_id, final_update); |
+} |
+ |
+#if defined(OS_ANDROID) |
+void FindRequestManager::ActivateNearestFindResult(float x, |
+ float y) { |
+ if (current_session_id_ == kInvalidId) |
+ return; |
+ |
+ auto rfh = contents_->GetMainFrame(); |
+ rfh->Send(new InputMsg_ActivateNearestFindResult( |
+ rfh->GetRoutingID(), current_session_id_, x, y)); |
+} |
+ |
+void FindRequestManager::RequestFindMatchRects(int current_version) { |
+ fmr_request_version_ = current_version; |
+ SendFindMatchRectsIPC(contents_->GetMainFrame()); |
+} |
+ |
+void FindRequestManager::FindMatchRectsReply( |
+ RenderFrameHost* rfh, |
+ int version, |
+ const std::vector<gfx::RectF>& rects, |
+ const gfx::RectF& active_rect) { |
+ contents_->FindMatchRectsReply(version, rects, active_rect); |
+} |
+#endif |
+ |
+void FindRequestManager::Reset(int new_session_id, |
+ const base::string16& new_search_text) { |
+ current_session_id_ = new_session_id; |
+ current_search_text_ = new_search_text; |
+ number_of_matches_ = 0; |
+ active_match_ordinal_ = 0; |
+ selection_rect_ = gfx::Rect(); |
+} |
+ |
+void FindRequestManager::SendFindIPC(int request_id, RenderFrameHost* rfh) { |
+ rfh->Send(new FrameMsg_Find(rfh->GetRoutingID(), request_id, |
+ current_search_text_, current_find_options_)); |
+} |
+ |
+void FindRequestManager::SendStopFindingIPC(StopFindAction action, |
+ RenderFrameHost* rfh) const { |
+ rfh->Send(new FrameMsg_StopFinding(rfh->GetRoutingID(), action)); |
+} |
+ |
+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
|
+ bool final_update) const { |
+ if (request_id == kInvalidId) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ |
+ contents_->FindReply(request_id, number_of_matches_, selection_rect_, |
+ active_match_ordinal_, final_update); |
+} |
+ |
+#if defined(OS_ANDROID) |
+void FindRequestManager::SendFindMatchRectsIPC(RenderFrameHost* rfh) { |
+ rfh->Send(new FrameMsg_FindMatchRects(rfh->GetRoutingID(), |
+ fmr_request_version_)); |
+} |
+#endif |
+ |
+} // namespace content |