OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_FIND_HELPER_H_ | 5 #ifndef EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_FIND_HELPER_H_ |
6 #define EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_FIND_HELPER_H_ | 6 #define EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_FIND_HELPER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 void CancelAllFindSessions(); | 29 void CancelAllFindSessions(); |
30 | 30 |
31 // Dispatches the |findupdate| event. | 31 // Dispatches the |findupdate| event. |
32 void DispatchFindUpdateEvent(bool canceled, bool final_update); | 32 void DispatchFindUpdateEvent(bool canceled, bool final_update); |
33 | 33 |
34 // Ends the find session with id |session_request_id| and calls the | 34 // Ends the find session with id |session_request_id| and calls the |
35 // appropriate callbacks. | 35 // appropriate callbacks. |
36 void EndFindSession(int session_request_id, bool canceled); | 36 void EndFindSession(int session_request_id, bool canceled); |
37 | 37 |
38 // Helper function for WebViewGuest::Find(). | 38 // Helper function for WebViewGuest::Find(). |
39 void Find( | 39 void Find(content::WebContents* guest_web_contents, |
40 content::WebContents* guest_web_contents, | 40 const base::string16& search_text, |
41 const base::string16& search_text, | 41 const blink::WebFindOptions& options, |
42 const blink::WebFindOptions& options, | 42 scoped_refptr<WebViewInternalFindFunction> find_function); |
43 scoped_refptr<WebViewInternalFindFunction> find_function); | |
44 | 43 |
45 // Helper function for WeViewGuest:FindReply(). | 44 // Helper function for WeViewGuest:FindReply(). |
46 void FindReply(int request_id, | 45 void FindReply(int request_id, |
47 int number_of_matches, | 46 int number_of_matches, |
48 const gfx::Rect& selection_rect, | 47 const gfx::Rect& selection_rect, |
49 int active_match_ordinal, | 48 int active_match_ordinal, |
50 bool final_update); | 49 bool final_update); |
51 | 50 |
52 private: | 51 private: |
53 // A wrapper to store find results. | 52 // A wrapper to store find results. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 private: | 93 private: |
95 const base::string16 search_text_; | 94 const base::string16 search_text_; |
96 FindResults find_results_; | 95 FindResults find_results_; |
97 | 96 |
98 DISALLOW_COPY_AND_ASSIGN(FindUpdateEvent); | 97 DISALLOW_COPY_AND_ASSIGN(FindUpdateEvent); |
99 }; | 98 }; |
100 | 99 |
101 // Handles all information about a find request and its results. | 100 // Handles all information about a find request and its results. |
102 class FindInfo { | 101 class FindInfo { |
103 public: | 102 public: |
104 FindInfo( | 103 FindInfo(int request_id, |
105 int request_id, | 104 const base::string16& search_text, |
106 const base::string16& search_text, | 105 const blink::WebFindOptions& options, |
107 const blink::WebFindOptions& options, | 106 scoped_refptr<WebViewInternalFindFunction> find_function); |
108 scoped_refptr<WebViewInternalFindFunction> find_function); | |
109 ~FindInfo(); | 107 ~FindInfo(); |
110 | 108 |
111 // Add another request to |find_next_requests_|. | 109 // Add another request to |find_next_requests_|. |
112 void AddFindNextRequest(const base::WeakPtr<FindInfo>& request) { | 110 void AddFindNextRequest(const base::WeakPtr<FindInfo>& request) { |
113 find_next_requests_.push_back(request); | 111 find_next_requests_.push_back(request); |
114 } | 112 } |
115 | 113 |
116 // Aggregate the find results. | 114 // Aggregate the find results. |
117 void AggregateResults(int number_of_matches, | 115 void AggregateResults(int number_of_matches, |
118 const gfx::Rect& selection_rect, | 116 const gfx::Rect& selection_rect, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // A find reply has been received for this find request. | 149 // A find reply has been received for this find request. |
152 bool replied_; | 150 bool replied_; |
153 | 151 |
154 // Stores pointers to all the find next requests if this is the first | 152 // Stores pointers to all the find next requests if this is the first |
155 // request of a find session. | 153 // request of a find session. |
156 std::vector<base::WeakPtr<FindInfo> > find_next_requests_; | 154 std::vector<base::WeakPtr<FindInfo> > find_next_requests_; |
157 | 155 |
158 friend void WebViewFindHelper::EndFindSession(int session_request_id, | 156 friend void WebViewFindHelper::EndFindSession(int session_request_id, |
159 bool canceled); | 157 bool canceled); |
160 | 158 |
161 // Weak pointer used to access the find info of fin. | |
162 base::WeakPtrFactory<FindInfo> weak_ptr_factory_; | 159 base::WeakPtrFactory<FindInfo> weak_ptr_factory_; |
163 | 160 |
164 DISALLOW_COPY_AND_ASSIGN(FindInfo); | 161 DISALLOW_COPY_AND_ASSIGN(FindInfo); |
165 }; | 162 }; |
166 | 163 |
167 // Pointer to the webview that is being helped. | 164 // Pointer to the webview that is being helped. |
168 WebViewGuest* const webview_guest_; | 165 WebViewGuest* const webview_guest_; |
169 | 166 |
170 // A counter to generate a unique request id for a find request. | 167 // A counter to generate a unique request id for a find request. |
171 // We only need the ids to be unique for a given WebViewGuest. | 168 // We only need the ids to be unique for a given WebViewGuest. |
172 int current_find_request_id_; | 169 int current_find_request_id_; |
173 | 170 |
174 // Stores aggregated find results and other info for the |findupdate| event. | 171 // Stores aggregated find results and other info for the |findupdate| event. |
175 scoped_ptr<FindUpdateEvent> find_update_event_; | 172 scoped_ptr<FindUpdateEvent> find_update_event_; |
176 | 173 |
177 // Pointer to the first request of the current find session. | 174 // Pointer to the first request of the current find session. |
178 linked_ptr<FindInfo> current_find_session_; | 175 linked_ptr<FindInfo> current_find_session_; |
179 | 176 |
180 // Stores each find request's information by request_id so that its callback | 177 // Stores each find request's information by request_id so that its callback |
181 // function can be called when its find results are available. | 178 // function can be called when its find results are available. |
182 typedef std::map<int, linked_ptr<FindInfo> > FindInfoMap; | 179 typedef std::map<int, linked_ptr<FindInfo> > FindInfoMap; |
183 FindInfoMap find_info_map_; | 180 FindInfoMap find_info_map_; |
184 | 181 |
185 DISALLOW_COPY_AND_ASSIGN(WebViewFindHelper); | 182 DISALLOW_COPY_AND_ASSIGN(WebViewFindHelper); |
186 }; | 183 }; |
187 | 184 |
188 } // namespace extensions | 185 } // namespace extensions |
189 | 186 |
190 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_FIND_HELPER_H_ | 187 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_WEB_VIEW_WEB_VIEW_FIND_HELPER_H_ |
OLD | NEW |