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..f40cd6c13e90cdccefe6ca776f36e353ed145b75 |
--- /dev/null |
+++ b/content/browser/find_request_manager.cc |
@@ -0,0 +1,149 @@ |
+// 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) |
+ : |
+#if defined(OS_ANDROID) |
+ 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.
|
+#endif |
+ contents_(web_contents), |
+ current_session_id_(kInvalidId), |
+ current_request_(), |
+ number_of_matches_(0), |
+ active_match_ordinal_(0) {} |
+ |
+FindRequestManager::~FindRequestManager() {} |
+ |
+void FindRequestManager::Find(int request_id, |
+ const base::string16& search_text, |
+ const blink::WebFindOptions& options) { |
+ // Every find request must have a unique ID, and these IDs must strictly |
+ // increase so that newer requests always have greater IDs than older |
+ // requests. |
+ DCHECK_GT(request_id, current_request_.id); |
+ DCHECK_GT(request_id, current_session_id_); |
+ |
+ 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.
|
+ |
+ if (options.findNext) { |
+ // This is a find next operation. |
+ |
+ // This implies that there is an ongoing find session with the same search |
+ // text. |
+ DCHECK_GE(current_session_id_, 0); |
+ DCHECK_EQ(request.search_text, current_request_.search_text); |
+ } else { |
+ // This is an initial find operation. |
+ Reset(request); |
+ } |
+ |
+ SendFindIPC(request, contents_->GetMainFrame()); |
+} |
+ |
+void FindRequestManager::StopFinding(StopFindAction action) { |
+ SendStopFindingIPC(action, contents_->GetMainFrame()); |
+ current_session_id_ = kInvalidId; |
+} |
+ |
+void FindRequestManager::OnFindReply(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; |
+ |
+ NotifyFindReply(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) { |
+ match_rects_.request_version = current_version; |
+ SendFindMatchRectsIPC(contents_->GetMainFrame()); |
+} |
+ |
+void FindRequestManager::OnFindMatchRectsReply( |
+ RenderFrameHost* rfh, |
+ int version, |
+ const std::vector<gfx::RectF>& rects, |
+ const gfx::RectF& active_rect) { |
+ contents_->NotifyFindMatchRectsReply(version, rects, active_rect); |
+} |
+#endif |
+ |
+void FindRequestManager::Reset(const FindRequest& initial_request) { |
+ current_session_id_ = initial_request.id; |
+ current_request_ = initial_request; |
+ number_of_matches_ = 0; |
+ active_match_ordinal_ = 0; |
+ selection_rect_ = gfx::Rect(); |
+#if defined(OS_ANDROID) |
+ 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
|
+#endif |
+} |
+ |
+void FindRequestManager::SendFindIPC(FindRequest request, |
lfg
2016/04/11 20:10:53
Pass by const reference.
paulmeyer
2016/04/12 17:54:25
Done.
|
+ RenderFrameHost* rfh) { |
+ rfh->Send(new FrameMsg_Find(rfh->GetRoutingID(), request.id, |
+ request.search_text, request.options)); |
+} |
+ |
+void FindRequestManager::SendStopFindingIPC(StopFindAction action, |
+ RenderFrameHost* rfh) const { |
+ rfh->Send(new FrameMsg_StopFinding(rfh->GetRoutingID(), action)); |
+} |
+ |
+void FindRequestManager::NotifyFindReply(int request_id, |
+ bool final_update) const { |
+ if (request_id == kInvalidId) { |
+ NOTREACHED(); |
+ return; |
+ } |
+ |
+ contents_->NotifyFindReply(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(), |
+ match_rects_.request_version)); |
+} |
+#endif |
+ |
+} // namespace content |