OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_FIND_REQUEST_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_FIND_REQUEST_MANAGER_H_ |
6 #define CONTENT_BROWSER_FIND_REQUEST_MANAGER_H_ | 6 #define CONTENT_BROWSER_FIND_REQUEST_MANAGER_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 #include <unordered_set> | 10 #include <unordered_set> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
16 #include "content/public/common/stop_find_action.h" | 16 #include "content/public/common/stop_find_action.h" |
17 #include "third_party/WebKit/public/web/WebFindOptions.h" | 17 #include "third_party/WebKit/public/web/WebFindOptions.h" |
18 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
19 #include "ui/gfx/geometry/rect_f.h" | 19 #include "ui/gfx/geometry/rect_f.h" |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 | 22 |
23 class RenderFrameHost; | 23 class RenderFrameHost; |
24 class WebContentsImpl; | 24 class WebContentsImpl; |
25 | 25 |
26 // FindRequestManager manages all of the find-in-page requests/replies | 26 // FindRequestManager manages all of the find-in-page requests/replies |
27 // initiated/received through a WebContents. It coordinates searching across | 27 // initiated/received through a WebContents. It coordinates searching across |
28 // multiple (potentially out-of-process) frames, handles the aggregation of find | 28 // multiple (potentially out-of-process) frames, handles the aggregation of find |
29 // results from each frame, and facilitates active match traversal. It is | 29 // results from each frame, and facilitates active match traversal. It is |
30 // instantiated once per top-level WebContents, and is owned by that | 30 // instantiated once per WebContents, and is owned by that WebContents. |
31 // WebContents. | 31 class CONTENT_EXPORT FindRequestManager : public WebContentsObserver { |
32 class CONTENT_EXPORT FindRequestManager { | |
33 public: | 32 public: |
34 explicit FindRequestManager(WebContentsImpl* web_contents); | 33 explicit FindRequestManager(WebContentsImpl* web_contents); |
35 ~FindRequestManager(); | 34 ~FindRequestManager() override; |
36 | 35 |
37 // Initiates a find operation for |search_text| with the options specified in | 36 // Initiates a find operation for |search_text| with the options specified in |
38 // |options|. |request_id| uniquely identifies the find request. | 37 // |options|. |request_id| uniquely identifies the find request. |
39 void Find(int request_id, | 38 void Find(int request_id, |
40 const base::string16& search_text, | 39 const base::string16& search_text, |
41 const blink::WebFindOptions& options); | 40 const blink::WebFindOptions& options); |
42 | 41 |
43 // Stops the active find session and clears the general highlighting of the | 42 // Stops the active find session and clears the general highlighting of the |
44 // matches. |action| determines whether the last active match (if any) will be | 43 // matches. |action| determines whether the last active match (if any) will be |
45 // activated, cleared, or remain highlighted. | 44 // activated, cleared, or remain highlighted. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 int version, | 77 int version, |
79 const std::vector<gfx::RectF>& rects, | 78 const std::vector<gfx::RectF>& rects, |
80 const gfx::RectF& active_rect); | 79 const gfx::RectF& active_rect); |
81 #endif | 80 #endif |
82 | 81 |
83 private: | 82 private: |
84 // An invalid ID. This value is invalid for any render process ID, render | 83 // An invalid ID. This value is invalid for any render process ID, render |
85 // frame ID, find request ID, or find match rects version number. | 84 // frame ID, find request ID, or find match rects version number. |
86 static const int kInvalidId; | 85 static const int kInvalidId; |
87 | 86 |
88 class FrameObserver; | |
89 | |
90 // The request data for a single find request. | 87 // The request data for a single find request. |
91 struct FindRequest { | 88 struct FindRequest { |
92 // The find request ID that uniquely identifies this find request. | 89 // The find request ID that uniquely identifies this find request. |
93 int id = kInvalidId; | 90 int id = kInvalidId; |
94 | 91 |
95 // The text that is being searched for in this find request. | 92 // The text that is being searched for in this find request. |
96 base::string16 search_text; | 93 base::string16 search_text; |
97 | 94 |
98 // The set of find options in effect for this find request. | 95 // The set of find options in effect for this find request. |
99 blink::WebFindOptions options; | 96 blink::WebFindOptions options; |
100 | 97 |
101 FindRequest() = default; | 98 FindRequest() = default; |
102 FindRequest(int id, | 99 FindRequest(int id, |
103 const base::string16& search_text, | 100 const base::string16& search_text, |
104 const blink::WebFindOptions& options) | 101 const blink::WebFindOptions& options) |
105 : id(id), search_text(search_text), options(options) {} | 102 : id(id), search_text(search_text), options(options) {} |
106 }; | 103 }; |
107 | 104 |
| 105 // WebContentsObserver implementation. |
| 106 void DidFinishLoad(RenderFrameHost* rfh, const GURL& validated_url) override; |
| 107 void RenderFrameDeleted(RenderFrameHost* rfh) override; |
| 108 void RenderFrameHostChanged(RenderFrameHost* old_host, |
| 109 RenderFrameHost* new_host) override; |
| 110 void FrameDeleted(RenderFrameHost* rfh) override; |
| 111 |
108 // Resets all of the per-session state for a new find-in-page session. | 112 // Resets all of the per-session state for a new find-in-page session. |
109 void Reset(const FindRequest& initial_request); | 113 void Reset(const FindRequest& initial_request); |
110 | 114 |
111 // Called internally as find requests come up in the queue. | 115 // Called internally as find requests come up in the queue. |
112 void FindInternal(const FindRequest& request); | 116 void FindInternal(const FindRequest& request); |
113 | 117 |
114 // Called when an informative response (a response with enough information to | 118 // Called when an informative response (a response with enough information to |
115 // be able to route subsequent find requests) comes in for the find request | 119 // be able to route subsequent find requests) comes in for the find request |
116 // with ID |request_id|. Advances the |find_request_queue_| if appropriate. | 120 // with ID |request_id|. Advances the |find_request_queue_| if appropriate. |
117 void AdvanceQueue(int request_id); | 121 void AdvanceQueue(int request_id); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 gfx::RectF active_rect; | 241 gfx::RectF active_rect; |
238 | 242 |
239 // Find match rects replies are still pending for these frames. | 243 // Find match rects replies are still pending for these frames. |
240 std::unordered_set<RenderFrameHost*> pending_replies; | 244 std::unordered_set<RenderFrameHost*> pending_replies; |
241 | 245 |
242 FindMatchRectsState(); | 246 FindMatchRectsState(); |
243 ~FindMatchRectsState(); | 247 ~FindMatchRectsState(); |
244 } match_rects_; | 248 } match_rects_; |
245 #endif | 249 #endif |
246 | 250 |
247 // The WebContents that owns this FindRequestManager. This also defines the | 251 // The WebContents that owns this FindRequestManager. |
248 // scope of all find sessions. Only frames in |contents_| and any inner | |
249 // WebContentses within it will be searched. | |
250 WebContentsImpl* const contents_; | 252 WebContentsImpl* const contents_; |
251 | 253 |
252 // The request ID of the initial find request in the current find-in-page | 254 // The request ID of the initial find request in the current find-in-page |
253 // session, which uniquely identifies this session. Request IDs are included | 255 // session, which uniquely identifies this session. Request IDs are included |
254 // in all find-related IPCs, which allows reply IPCs containing results from | 256 // in all find-related IPCs, which allows reply IPCs containing results from |
255 // previous sessions (with |request_id| < |current_session_id_|) to be easily | 257 // previous sessions (with |request_id| < |current_session_id_|) to be easily |
256 // identified and ignored. | 258 // identified and ignored. |
257 int current_session_id_; | 259 int current_session_id_; |
258 | 260 |
259 // The current find request. | 261 // The current find request. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 // The rectangle around the active match, in screen coordinates. | 299 // The rectangle around the active match, in screen coordinates. |
298 gfx::Rect selection_rect_; | 300 gfx::Rect selection_rect_; |
299 | 301 |
300 // Find requests are queued here when previous requests need to be handled | 302 // Find requests are queued here when previous requests need to be handled |
301 // before these ones can be properly routed. | 303 // before these ones can be properly routed. |
302 std::queue<FindRequest> find_request_queue_; | 304 std::queue<FindRequest> find_request_queue_; |
303 | 305 |
304 // Keeps track of the find request ID of the last find reply reported via | 306 // Keeps track of the find request ID of the last find reply reported via |
305 // NotifyFindReply(). | 307 // NotifyFindReply(). |
306 int last_reported_id_; | 308 int last_reported_id_; |
307 | |
308 // WebContentsObservers to observe frame changes in |contents_| and its inner | |
309 // WebContentses. | |
310 std::vector<std::unique_ptr<FrameObserver>> frame_observers_; | |
311 | |
312 DISALLOW_COPY_AND_ASSIGN(FindRequestManager); | |
313 }; | 309 }; |
314 | 310 |
315 } // namespace content | 311 } // namespace content |
316 | 312 |
317 #endif // CONTENT_BROWSER_FIND_REQUEST_MANAGER_H_ | 313 #endif // CONTENT_BROWSER_FIND_REQUEST_MANAGER_H_ |
OLD | NEW |