OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "components/web_view/find_controller.h" | 5 #include "components/web_view/find_controller.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/trace_event/trace_event.h" |
9 #include "components/web_view/find_controller_delegate.h" | 10 #include "components/web_view/find_controller_delegate.h" |
10 #include "components/web_view/frame.h" | 11 #include "components/web_view/frame.h" |
11 | 12 |
12 namespace web_view { | 13 namespace web_view { |
13 | 14 |
14 FindController::FindController(FindControllerDelegate* delegate) | 15 FindController::FindController(FindControllerDelegate* delegate) |
15 : delegate_(delegate), | 16 : delegate_(delegate), |
16 find_request_id_counter_(0), | 17 find_request_id_counter_(0), |
17 current_find_request_id_(-1), | 18 current_find_request_id_(-1), |
18 frame_with_selection_(0), | 19 frame_with_selection_(0), |
19 weak_ptr_factory_(this) {} | 20 weak_ptr_factory_(this) {} |
20 | 21 |
21 FindController::~FindController() {} | 22 FindController::~FindController() {} |
22 | 23 |
23 void FindController::Find(const std::string& in_search_string, | 24 void FindController::Find(const std::string& in_search_string, |
24 bool forward_direction) { | 25 bool forward_direction) { |
| 26 TRACE_EVENT2("web_view", "FindController::Find", |
| 27 "search_string", in_search_string, |
| 28 "forward_direction", forward_direction); |
25 std::string search_string = in_search_string; | 29 std::string search_string = in_search_string; |
26 // Remove the carriage return character, which generally isn't in web content. | 30 // Remove the carriage return character, which generally isn't in web content. |
27 const char kInvalidChars[] = {'\r', 0}; | 31 const char kInvalidChars[] = {'\r', 0}; |
28 base::RemoveChars(search_string, kInvalidChars, &search_string); | 32 base::RemoveChars(search_string, kInvalidChars, &search_string); |
29 | 33 |
30 previous_find_text_ = find_text_; | 34 previous_find_text_ = find_text_; |
31 | 35 |
32 // TODO(erg): Do we need to something like |find_op_aborted_|? | 36 // TODO(erg): Do we need to something like |find_op_aborted_|? |
33 | 37 |
34 find_frames_in_order_ = delegate_->GetAllFrames(); | 38 find_frames_in_order_ = delegate_->GetAllFrames(); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 if (it != find_frames_in_order_.end()) | 121 if (it != find_frames_in_order_.end()) |
118 find_frames_in_order_.erase(it); | 122 find_frames_in_order_.erase(it); |
119 } | 123 } |
120 | 124 |
121 void FindController::OnContinueFinding(int32_t request_id, | 125 void FindController::OnContinueFinding(int32_t request_id, |
122 const std::string& search_string, | 126 const std::string& search_string, |
123 LocalFindOptions options, | 127 LocalFindOptions options, |
124 uint32_t starting_frame, | 128 uint32_t starting_frame, |
125 uint32_t current_frame, | 129 uint32_t current_frame, |
126 bool found) { | 130 bool found) { |
| 131 TRACE_EVENT2("web_view", "FindController::OnContinueFinding", |
| 132 "request_id", request_id, |
| 133 "search_string", search_string); |
127 if (!found) { | 134 if (!found) { |
128 // So we need to figure out what the next frame to search is. | 135 // So we need to figure out what the next frame to search is. |
129 Frame* next_frame = | 136 Frame* next_frame = |
130 GetNextFrameToSearch(starting_frame, current_frame, options.forward); | 137 GetNextFrameToSearch(starting_frame, current_frame, options.forward); |
131 | 138 |
132 // If we have one more frame to search: | 139 // If we have one more frame to search: |
133 if (next_frame) { | 140 if (next_frame) { |
134 bool wrap_within_frame = find_frames_in_order_.size() == 1; | 141 bool wrap_within_frame = find_frames_in_order_.size() == 1; |
135 next_frame->Find( | 142 next_frame->Find( |
136 request_id, mojo::String::From(search_string), | 143 request_id, mojo::String::From(search_string), |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 std::vector<Frame*>::iterator FindController::GetFrameIteratorById( | 229 std::vector<Frame*>::iterator FindController::GetFrameIteratorById( |
223 uint32_t frame_id) { | 230 uint32_t frame_id) { |
224 return find_if(find_frames_in_order_.begin(), | 231 return find_if(find_frames_in_order_.begin(), |
225 find_frames_in_order_.end(), | 232 find_frames_in_order_.end(), |
226 [&frame_id](Frame* f) { | 233 [&frame_id](Frame* f) { |
227 return f->id() == frame_id; | 234 return f->id() == frame_id; |
228 }); | 235 }); |
229 } | 236 } |
230 | 237 |
231 } // namespace web_view | 238 } // namespace web_view |
OLD | NEW |