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

Side by Side Diff: components/autofill/content/renderer/password_autofill_agent.cc

Issue 1220653002: Fix some case-insensitive cases for StartsWith (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: grt's review comments, Mac fix Created 5 years, 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/autofill/content/renderer/password_autofill_agent.h" 5 #include "components/autofill/content/renderer/password_autofill_agent.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/i18n/case_conversion.h"
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
12 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "components/autofill/content/common/autofill_messages.h" 15 #include "components/autofill/content/common/autofill_messages.h"
15 #include "components/autofill/content/renderer/form_autofill_util.h" 16 #include "components/autofill/content/renderer/form_autofill_util.h"
16 #include "components/autofill/content/renderer/password_form_conversion_utils.h" 17 #include "components/autofill/content/renderer/password_form_conversion_utils.h"
17 #include "components/autofill/content/renderer/renderer_save_password_progress_l ogger.h" 18 #include "components/autofill/content/renderer/renderer_save_password_progress_l ogger.h"
18 #include "components/autofill/core/common/autofill_constants.h" 19 #include "components/autofill/core/common/autofill_constants.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 219
219 bool IsElementEditable(const blink::WebInputElement& element) { 220 bool IsElementEditable(const blink::WebInputElement& element) {
220 return element.isEnabled() && !element.isReadOnly(); 221 return element.isEnabled() && !element.isReadOnly();
221 } 222 }
222 223
223 bool DoUsernamesMatch(const base::string16& username1, 224 bool DoUsernamesMatch(const base::string16& username1,
224 const base::string16& username2, 225 const base::string16& username2,
225 bool exact_match) { 226 bool exact_match) {
226 if (exact_match) 227 if (exact_match)
227 return username1 == username2; 228 return username1 == username2;
228 return base::StartsWith(username1, username2, true); 229 return base::StartsWith(username1, username2, base::CompareCase::SENSITIVE);
229 } 230 }
230 231
231 // Returns |true| if the given element is editable. Otherwise, returns |false|. 232 // Returns |true| if the given element is editable. Otherwise, returns |false|.
232 bool IsElementAutocompletable(const blink::WebInputElement& element) { 233 bool IsElementAutocompletable(const blink::WebInputElement& element) {
233 return IsElementEditable(element); 234 return IsElementEditable(element);
234 } 235 }
235 236
236 // Returns true if the password specified in |form| is a default value. 237 // Returns true if the password specified in |form| is a default value.
237 bool PasswordValueIsDefault(const base::string16& password_element, 238 bool PasswordValueIsDefault(const base::string16& password_element,
238 const base::string16& password_value, 239 const base::string16& password_value,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // Sets |suggestions_present| to true if there are any suggestions to be derived 278 // Sets |suggestions_present| to true if there are any suggestions to be derived
278 // from |fill_data|. Unless |show_all| is true, only considers suggestions with 279 // from |fill_data|. Unless |show_all| is true, only considers suggestions with
279 // usernames having |current_username| as a prefix. Returns true if a username 280 // usernames having |current_username| as a prefix. Returns true if a username
280 // from the |fill_data.other_possible_usernames| would be included in the 281 // from the |fill_data.other_possible_usernames| would be included in the
281 // suggestions. 282 // suggestions.
282 bool GetSuggestionsStats(const PasswordFormFillData& fill_data, 283 bool GetSuggestionsStats(const PasswordFormFillData& fill_data,
283 const base::string16& current_username, 284 const base::string16& current_username,
284 bool show_all, 285 bool show_all,
285 bool* suggestions_present) { 286 bool* suggestions_present) {
286 *suggestions_present = false; 287 *suggestions_present = false;
288 base::string16 current_username_lower = base::i18n::ToLower(current_username);
287 289
288 for (const auto& usernames : fill_data.other_possible_usernames) { 290 for (const auto& usernames : fill_data.other_possible_usernames) {
289 for (size_t i = 0; i < usernames.second.size(); ++i) { 291 for (size_t i = 0; i < usernames.second.size(); ++i) {
290 if (show_all || 292 if (show_all ||
291 base::StartsWith(usernames.second[i], current_username, false)) { 293 base::StartsWith(
294 base::i18n::ToLower(base::string16(usernames.second[i])),
295 current_username_lower, base::CompareCase::SENSITIVE)) {
292 *suggestions_present = true; 296 *suggestions_present = true;
293 return true; 297 return true;
294 } 298 }
295 } 299 }
296 } 300 }
297 301
298 if (show_all || base::StartsWith(fill_data.username_field.value, 302 if (show_all ||
299 current_username, false)) { 303 base::StartsWith(base::i18n::ToLower(fill_data.username_field.value),
304 current_username_lower, base::CompareCase::SENSITIVE)) {
300 *suggestions_present = true; 305 *suggestions_present = true;
301 return false; 306 return false;
302 } 307 }
303 308
304 for (const auto& login : fill_data.additional_logins) { 309 for (const auto& login : fill_data.additional_logins) {
305 if (show_all || base::StartsWith(login.first, current_username, false)) { 310 if (show_all ||
311 base::StartsWith(base::i18n::ToLower(login.first),
312 current_username_lower,
313 base::CompareCase::SENSITIVE)) {
306 *suggestions_present = true; 314 *suggestions_present = true;
307 return false; 315 return false;
308 } 316 }
309 } 317 }
310 318
311 return false; 319 return false;
312 } 320 }
313 321
314 // Returns true if there exists a credential suggestion whose username field is 322 // Returns true if there exists a credential suggestion whose username field is
315 // an exact match to the current username (not just a prefix). 323 // an exact match to the current username (not just a prefix).
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { 1498 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() {
1491 agent_->DidStopLoading(); 1499 agent_->DidStopLoading();
1492 } 1500 }
1493 1501
1494 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: 1502 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::
1495 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { 1503 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) {
1496 agent_->LegacyDidStartProvisionalLoad(navigated_frame); 1504 agent_->LegacyDidStartProvisionalLoad(navigated_frame);
1497 } 1505 }
1498 1506
1499 } // namespace autofill 1507 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698