Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: content/browser/find_request_manager.h

Issue 2700613003: Enable find-in-page across GuestViews. (Closed)
Patch Set: Small fix. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 WebContents, and is owned by that WebContents. 30 // instantiated once per top-level WebContents, and is owned by that
31 class CONTENT_EXPORT FindRequestManager : public WebContentsObserver { 31 // WebContents.
32 class CONTENT_EXPORT FindRequestManager {
32 public: 33 public:
33 explicit FindRequestManager(WebContentsImpl* web_contents); 34 explicit FindRequestManager(WebContentsImpl* web_contents);
34 ~FindRequestManager() override; 35 ~FindRequestManager();
35 36
36 // Initiates a find operation for |search_text| with the options specified in 37 // Initiates a find operation for |search_text| with the options specified in
37 // |options|. |request_id| uniquely identifies the find request. 38 // |options|. |request_id| uniquely identifies the find request.
38 void Find(int request_id, 39 void Find(int request_id,
39 const base::string16& search_text, 40 const base::string16& search_text,
40 const blink::WebFindOptions& options); 41 const blink::WebFindOptions& options);
41 42
42 // Stops the active find session and clears the general highlighting of the 43 // Stops the active find session and clears the general highlighting of the
43 // matches. |action| determines whether the last active match (if any) will be 44 // matches. |action| determines whether the last active match (if any) will be
44 // activated, cleared, or remain highlighted. 45 // activated, cleared, or remain highlighted.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 int version, 78 int version,
78 const std::vector<gfx::RectF>& rects, 79 const std::vector<gfx::RectF>& rects,
79 const gfx::RectF& active_rect); 80 const gfx::RectF& active_rect);
80 #endif 81 #endif
81 82
82 private: 83 private:
83 // An invalid ID. This value is invalid for any render process ID, render 84 // An invalid ID. This value is invalid for any render process ID, render
84 // frame ID, find request ID, or find match rects version number. 85 // frame ID, find request ID, or find match rects version number.
85 static const int kInvalidId; 86 static const int kInvalidId;
86 87
88 class FrameObserver;
89
87 // The request data for a single find request. 90 // The request data for a single find request.
88 struct FindRequest { 91 struct FindRequest {
89 // The find request ID that uniquely identifies this find request. 92 // The find request ID that uniquely identifies this find request.
90 int id = kInvalidId; 93 int id = kInvalidId;
91 94
92 // The text that is being searched for in this find request. 95 // The text that is being searched for in this find request.
93 base::string16 search_text; 96 base::string16 search_text;
94 97
95 // The set of find options in effect for this find request. 98 // The set of find options in effect for this find request.
96 blink::WebFindOptions options; 99 blink::WebFindOptions options;
97 100
98 FindRequest() = default; 101 FindRequest() = default;
99 FindRequest(int id, 102 FindRequest(int id,
100 const base::string16& search_text, 103 const base::string16& search_text,
101 const blink::WebFindOptions& options) 104 const blink::WebFindOptions& options)
102 : id(id), search_text(search_text), options(options) {} 105 : id(id), search_text(search_text), options(options) {}
103 }; 106 };
104 107
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
112 // Resets all of the per-session state for a new find-in-page session. 108 // Resets all of the per-session state for a new find-in-page session.
113 void Reset(const FindRequest& initial_request); 109 void Reset(const FindRequest& initial_request);
114 110
115 // Called internally as find requests come up in the queue. 111 // Called internally as find requests come up in the queue.
116 void FindInternal(const FindRequest& request); 112 void FindInternal(const FindRequest& request);
117 113
118 // Called when an informative response (a response with enough information to 114 // Called when an informative response (a response with enough information to
119 // be able to route subsequent find requests) comes in for the find request 115 // be able to route subsequent find requests) comes in for the find request
120 // with ID |request_id|. Advances the |find_request_queue_| if appropriate. 116 // with ID |request_id|. Advances the |find_request_queue_| if appropriate.
121 void AdvanceQueue(int request_id); 117 void AdvanceQueue(int request_id);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 gfx::RectF active_rect; 237 gfx::RectF active_rect;
242 238
243 // Find match rects replies are still pending for these frames. 239 // Find match rects replies are still pending for these frames.
244 std::unordered_set<RenderFrameHost*> pending_replies; 240 std::unordered_set<RenderFrameHost*> pending_replies;
245 241
246 FindMatchRectsState(); 242 FindMatchRectsState();
247 ~FindMatchRectsState(); 243 ~FindMatchRectsState();
248 } match_rects_; 244 } match_rects_;
249 #endif 245 #endif
250 246
251 // The WebContents that owns this FindRequestManager. 247 // The WebContents that owns this FindRequestManager. This also defines the
248 // scope of all find sessions. Only frames in |contents_| and any inner
249 // WebContentses within it will be searched.
252 WebContentsImpl* const contents_; 250 WebContentsImpl* const contents_;
253 251
254 // The request ID of the initial find request in the current find-in-page 252 // The request ID of the initial find request in the current find-in-page
255 // session, which uniquely identifies this session. Request IDs are included 253 // session, which uniquely identifies this session. Request IDs are included
256 // in all find-related IPCs, which allows reply IPCs containing results from 254 // in all find-related IPCs, which allows reply IPCs containing results from
257 // previous sessions (with |request_id| < |current_session_id_|) to be easily 255 // previous sessions (with |request_id| < |current_session_id_|) to be easily
258 // identified and ignored. 256 // identified and ignored.
259 int current_session_id_; 257 int current_session_id_;
260 258
261 // The current find request. 259 // The current find request.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // The rectangle around the active match, in screen coordinates. 297 // The rectangle around the active match, in screen coordinates.
300 gfx::Rect selection_rect_; 298 gfx::Rect selection_rect_;
301 299
302 // Find requests are queued here when previous requests need to be handled 300 // Find requests are queued here when previous requests need to be handled
303 // before these ones can be properly routed. 301 // before these ones can be properly routed.
304 std::queue<FindRequest> find_request_queue_; 302 std::queue<FindRequest> find_request_queue_;
305 303
306 // Keeps track of the find request ID of the last find reply reported via 304 // Keeps track of the find request ID of the last find reply reported via
307 // NotifyFindReply(). 305 // NotifyFindReply().
308 int last_reported_id_; 306 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);
309 }; 313 };
310 314
311 } // namespace content 315 } // namespace content
312 316
313 #endif // CONTENT_BROWSER_FIND_REQUEST_MANAGER_H_ 317 #endif // CONTENT_BROWSER_FIND_REQUEST_MANAGER_H_
OLDNEW
« no previous file with comments | « content/browser/browser_plugin/browser_plugin_guest.cc ('k') | content/browser/find_request_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698