| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/find_bar/find_tab_helper.h" | 5 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // static | 28 // static |
| 29 int FindTabHelper::find_request_id_counter_ = -1; | 29 int FindTabHelper::find_request_id_counter_ = -1; |
| 30 | 30 |
| 31 FindTabHelper::FindTabHelper(WebContents* web_contents) | 31 FindTabHelper::FindTabHelper(WebContents* web_contents) |
| 32 : content::WebContentsObserver(web_contents), | 32 : content::WebContentsObserver(web_contents), |
| 33 find_ui_active_(false), | 33 find_ui_active_(false), |
| 34 find_op_aborted_(false), | 34 find_op_aborted_(false), |
| 35 current_find_request_id_(find_request_id_counter_++), | 35 current_find_request_id_(find_request_id_counter_++), |
| 36 current_find_session_id_(current_find_request_id_), | 36 current_find_session_id_(current_find_request_id_), |
| 37 last_search_case_sensitive_(false), | 37 last_search_case_sensitive_(false), |
| 38 last_search_result_() { | 38 last_search_result_(), |
| 39 } | 39 final_update_received_for_current_query_(false) {} |
| 40 | 40 |
| 41 FindTabHelper::~FindTabHelper() { | 41 FindTabHelper::~FindTabHelper() { |
| 42 } | 42 } |
| 43 | 43 |
| 44 void FindTabHelper::StartFinding(base::string16 search_string, | 44 void FindTabHelper::StartFinding(base::string16 search_string, |
| 45 bool forward_direction, | 45 bool forward_direction, |
| 46 bool case_sensitive) { | 46 bool case_sensitive) { |
| 47 // Remove the carriage return character, which generally isn't in web content. | 47 // Remove the carriage return character, which generally isn't in web content. |
| 48 const base::char16 kInvalidChars[] = { '\r', 0 }; | 48 const base::char16 kInvalidChars[] = { '\r', 0 }; |
| 49 base::RemoveChars(search_string, kInvalidChars, &search_string); | 49 base::RemoveChars(search_string, kInvalidChars, &search_string); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 current_find_request_id_ = find_request_id_counter_++; | 82 current_find_request_id_ = find_request_id_counter_++; |
| 83 if (!find_next) | 83 if (!find_next) |
| 84 current_find_session_id_ = current_find_request_id_; | 84 current_find_session_id_ = current_find_request_id_; |
| 85 | 85 |
| 86 if (!search_string.empty()) | 86 if (!search_string.empty()) |
| 87 find_text_ = search_string; | 87 find_text_ = search_string; |
| 88 last_search_case_sensitive_ = case_sensitive; | 88 last_search_case_sensitive_ = case_sensitive; |
| 89 | 89 |
| 90 find_op_aborted_ = false; | 90 find_op_aborted_ = false; |
| 91 final_update_received_for_current_query_ = false; |
| 91 | 92 |
| 92 // Keep track of what the last search was across the tabs. | 93 // Keep track of what the last search was across the tabs. |
| 93 Profile* profile = | 94 Profile* profile = |
| 94 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 95 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 95 FindBarState* find_bar_state = FindBarStateFactory::GetForProfile(profile); | 96 FindBarState* find_bar_state = FindBarStateFactory::GetForProfile(profile); |
| 96 find_bar_state->set_last_prepopulate_text(find_text_); | 97 find_bar_state->set_last_prepopulate_text(find_text_); |
| 97 | 98 |
| 98 WebFindOptions options; | 99 WebFindOptions options; |
| 99 options.forward = forward_direction; | 100 options.forward = forward_direction; |
| 100 options.matchCase = case_sensitive; | 101 options.matchCase = case_sensitive; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 number_of_matches = last_search_result_.number_of_matches(); | 168 number_of_matches = last_search_result_.number_of_matches(); |
| 168 if (active_match_ordinal == -1) | 169 if (active_match_ordinal == -1) |
| 169 active_match_ordinal = last_search_result_.active_match_ordinal(); | 170 active_match_ordinal = last_search_result_.active_match_ordinal(); |
| 170 | 171 |
| 171 gfx::Rect selection = selection_rect; | 172 gfx::Rect selection = selection_rect; |
| 172 if (final_update && active_match_ordinal == 0) | 173 if (final_update && active_match_ordinal == 0) |
| 173 selection = gfx::Rect(); | 174 selection = gfx::Rect(); |
| 174 else if (selection_rect.IsEmpty()) | 175 else if (selection_rect.IsEmpty()) |
| 175 selection = last_search_result_.selection_rect(); | 176 selection = last_search_result_.selection_rect(); |
| 176 | 177 |
| 178 // Don't report more than one "final update" for a given query. See |
| 179 // https://crbug.com/682299. |
| 180 if (final_update) { |
| 181 if (final_update_received_for_current_query_) |
| 182 final_update = false; |
| 183 else |
| 184 final_update_received_for_current_query_ = true; |
| 185 } |
| 186 |
| 177 // Notify the UI, automation and any other observers that a find result was | 187 // Notify the UI, automation and any other observers that a find result was |
| 178 // found. | 188 // found. |
| 179 last_search_result_ = FindNotificationDetails( | 189 last_search_result_ = FindNotificationDetails( |
| 180 request_id, number_of_matches, selection, active_match_ordinal, | 190 request_id, number_of_matches, selection, active_match_ordinal, |
| 181 final_update); | 191 final_update); |
| 182 content::NotificationService::current()->Notify( | 192 content::NotificationService::current()->Notify( |
| 183 chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, | 193 chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, |
| 184 content::Source<WebContents>(web_contents()), | 194 content::Source<WebContents>(web_contents()), |
| 185 content::Details<FindNotificationDetails>(&last_search_result_)); | 195 content::Details<FindNotificationDetails>(&last_search_result_)); |
| 186 } | 196 } |
| 187 } | 197 } |
| OLD | NEW |