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 #ifndef CONTENT_BROWSER_FIND_REQUEST_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_FIND_REQUEST_MANAGER_H_ |
| 7 |
| 8 #include <set> |
| 9 #include <vector> |
| 10 |
| 11 #include "content/public/common/stop_find_action.h" |
| 12 #include "third_party/WebKit/public/web/WebFindOptions.h" |
| 13 #include "ui/gfx/geometry/rect.h" |
| 14 #include "ui/gfx/geometry/rect_f.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 class RenderFrameHost; |
| 19 class WebContentsImpl; |
| 20 |
| 21 // FindRequestManager manages all of the find-in-page requests/replies |
| 22 // initiated/received through a WebContents. It coordinates searching across |
| 23 // multiple (potentially out-of-process) frames, handles the aggregation of find |
| 24 // results from each frame, and facilitates active match traversal. It is |
| 25 // instantiated once per WebContents, and is owned by that WebContents. |
| 26 // |
| 27 // TODO(paulmeyer): FindRequestManager is currently incomplete and does not do |
| 28 // all of these things yet, but will soon. |
| 29 class FindRequestManager { |
| 30 public: |
| 31 explicit FindRequestManager(WebContentsImpl* web_contents); |
| 32 ~FindRequestManager(); |
| 33 |
| 34 // Initiates a find operation for |search_text| with the options specified in |
| 35 // |options|. |request_id| uniquely identifies the find request. |
| 36 void Find(int request_id, |
| 37 const base::string16& search_text, |
| 38 const blink::WebFindOptions& options); |
| 39 |
| 40 // Stops the active find session and clears the general highlighting of the |
| 41 // matches. |action| determines whether the last active match (if any) will be |
| 42 // activated, cleared, or remain highlighted. |
| 43 void StopFinding(StopFindAction action); |
| 44 |
| 45 // Called when a reply is received from a frame with the results from a |
| 46 // find request. |
| 47 void OnFindReply(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 |
| 54 #if defined(OS_ANDROID) |
| 55 // Selects and zooms to the find result nearest to the point (x,y) defined in |
| 56 // find-in-page coordinates. |
| 57 void ActivateNearestFindResult(float x, float y); |
| 58 |
| 59 // Requests the rects of the current find matches from the renderer process. |
| 60 void RequestFindMatchRects(int current_version); |
| 61 |
| 62 // Called when a reply is received in response to a request for find match |
| 63 // rects. |
| 64 void OnFindMatchRectsReply(RenderFrameHost* rfh, |
| 65 int version, |
| 66 const std::vector<gfx::RectF>& rects, |
| 67 const gfx::RectF& active_rect); |
| 68 #endif |
| 69 |
| 70 private: |
| 71 // An invalid ID. This value is invalid for any render process ID, render |
| 72 // frame ID, or find request ID. |
| 73 static const int kInvalidId; |
| 74 |
| 75 // The request data for a single find request. |
| 76 struct FindRequest { |
| 77 // The find request ID that uniquely identifies this find request. |
| 78 int id = kInvalidId; |
| 79 |
| 80 // The text that is being searched for in this find request. |
| 81 base::string16 search_text; |
| 82 |
| 83 // The set of find options in effect for this find request. |
| 84 blink::WebFindOptions options; |
| 85 |
| 86 FindRequest() = default; |
| 87 FindRequest(int id, |
| 88 const base::string16& search_text, |
| 89 const blink::WebFindOptions& options) |
| 90 : id(id), search_text(search_text), options(options) {} |
| 91 }; |
| 92 |
| 93 // Send a find IPC containing the find request |request| to the RenderFrame |
| 94 // associated with |rfh|. |
| 95 void SendFindIPC(const FindRequest& request, RenderFrameHost* rfh); |
| 96 |
| 97 // Send a stop finding IPC to the RenderFrame associated with |rfh|. |
| 98 void SendStopFindingIPC(StopFindAction action, RenderFrameHost* rfh) const; |
| 99 |
| 100 // Reset all of the per-session state for a new find-in-page session. |
| 101 void Reset(const FindRequest& initial_request); |
| 102 |
| 103 // Send the find results (as they currently are) to the WebContents. |
| 104 void NotifyFindReply(int request_id, bool final_update) const; |
| 105 |
| 106 #if defined(OS_ANDROID) |
| 107 // Request the latest find match rects from a frame. |
| 108 void SendFindMatchRectsIPC(RenderFrameHost* rfh); |
| 109 |
| 110 // State related to FindMatchRects requests. |
| 111 struct FindMatchRectsState { |
| 112 // The latest find match rects version known by the requester. |
| 113 int request_version = kInvalidId; |
| 114 } match_rects_; |
| 115 #endif |
| 116 |
| 117 // The WebContents that owns this FindRequestManager. |
| 118 WebContentsImpl* const contents_; |
| 119 |
| 120 // The request ID of the initial find request in the current find-in-page |
| 121 // session, which uniquely identifies this session. Request IDs are included |
| 122 // in all find-related IPCs, which allows reply IPCs containing results from |
| 123 // previous sessions (with |request_id| < |current_session_id_|) to be easily |
| 124 // identified and ignored. |
| 125 int current_session_id_; |
| 126 |
| 127 // The current find request. |
| 128 FindRequest current_request_; |
| 129 |
| 130 // The total number of matches found in the current find-in-page session. |
| 131 int number_of_matches_; |
| 132 |
| 133 // The overall active match ordinal for the current find-in-page session. |
| 134 int active_match_ordinal_; |
| 135 |
| 136 // The rectangle around the active match, in screen coordinates. |
| 137 gfx::Rect selection_rect_; |
| 138 }; |
| 139 |
| 140 } // namespace content |
| 141 |
| 142 #endif // CONTENT_BROWSER_FIND_REQUEST_MANAGER_H_ |
OLD | NEW |