| 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..4ffda30f2466c43ae5a0f0a7285325744aacf89c
|
| --- /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_request_id_(kInvalidId),
|
| + 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) {
|
| + DCHECK(request_id > current_request_id_);
|
| + 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_request_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_request_id_ == kInvalidId || request_id < current_request_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_request_id_ == kInvalidId)
|
| + return;
|
| +
|
| + auto rfh = contents_->GetMainFrame();
|
| + rfh->Send(new InputMsg_ActivateNearestFindResult(
|
| + rfh->GetRoutingID(), current_request_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_request_id,
|
| + const base::string16& new_search_text) {
|
| + current_request_id_ = new_request_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,
|
| + 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
|
|
|