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

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

Issue 2771833002: Password Manager should skip fields with credit card autocomplete attribute. (Closed)
Patch Set: Add comment Created 3 years, 9 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_form_conversion_utils.h" 5 #include "components/autofill/content/renderer/password_form_conversion_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 // (N*PPP?.*) and forms which use password fields to store private but 86 // (N*PPP?.*) and forms which use password fields to store private but
87 // non-password data (could look like, e.g., PN+P.*). 87 // non-password data (could look like, e.g., PN+P.*).
88 const char kLoginAndSignupRegex[] = 88 const char kLoginAndSignupRegex[] =
89 "NP" // Login section. 89 "NP" // Login section.
90 "N+P" // Sign-up section. 90 "N+P" // Sign-up section.
91 ".*"; // Anything beyond that. 91 ".*"; // Anything beyond that.
92 92
93 const char kAutocompleteUsername[] = "username"; 93 const char kAutocompleteUsername[] = "username";
94 const char kAutocompleteCurrentPassword[] = "current-password"; 94 const char kAutocompleteCurrentPassword[] = "current-password";
95 const char kAutocompleteNewPassword[] = "new-password"; 95 const char kAutocompleteNewPassword[] = "new-password";
96 const char kAutocompleteCreditCardPrefix[] = "cc-";
96 97
97 re2::RE2* CreateMatcher(void* instance, const char* pattern) { 98 re2::RE2* CreateMatcher(void* instance, const char* pattern) {
98 re2::RE2::Options options; 99 re2::RE2::Options options;
99 options.set_case_sensitive(false); 100 options.set_case_sensitive(false);
100 // Use placement new to initialize the instance in the preallocated space. 101 // Use placement new to initialize the instance in the preallocated space.
101 // The "(instance)" is very important to force POD type initialization. 102 // The "(instance)" is very important to force POD type initialization.
102 re2::RE2* matcher = new (instance) re2::RE2(pattern, options); 103 re2::RE2* matcher = new (instance) re2::RE2(pattern, options);
103 DCHECK(matcher->ok()); 104 DCHECK(matcher->ok());
104 return matcher; 105 return matcher;
105 } 106 }
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 std::string layout_sequence; 419 std::string layout_sequence;
419 layout_sequence.reserve(form.control_elements.size()); 420 layout_sequence.reserve(form.control_elements.size());
420 size_t number_of_non_empty_text_non_password_fields = 0; 421 size_t number_of_non_empty_text_non_password_fields = 0;
421 for (size_t i = 0; i < form.control_elements.size(); ++i) { 422 for (size_t i = 0; i < form.control_elements.size(); ++i) {
422 WebFormControlElement control_element = form.control_elements[i]; 423 WebFormControlElement control_element = form.control_elements[i];
423 424
424 WebInputElement* input_element = toWebInputElement(&control_element); 425 WebInputElement* input_element = toWebInputElement(&control_element);
425 if (!input_element || !input_element->isEnabled()) 426 if (!input_element || !input_element->isEnabled())
426 continue; 427 continue;
427 428
429 if (HasCreditCardAutocompleteAttributes(*input_element))
430 continue;
431
428 bool element_is_invisible = !form_util::IsWebNodeVisible(*input_element); 432 bool element_is_invisible = !form_util::IsWebNodeVisible(*input_element);
429 if (input_element->isTextField()) { 433 if (input_element->isTextField()) {
430 if (input_element->isPasswordField()) { 434 if (input_element->isPasswordField()) {
431 if (element_is_invisible && ignore_invisible_passwords) 435 if (element_is_invisible && ignore_invisible_passwords)
432 continue; 436 continue;
433 layout_sequence.push_back('P'); 437 layout_sequence.push_back('P');
434 } else { 438 } else {
435 if (FieldHasNonscriptModifiedValue(field_value_and_properties_map, 439 if (FieldHasNonscriptModifiedValue(field_value_and_properties_map,
436 *input_element)) 440 *input_element))
437 ++number_of_non_empty_text_non_password_fields; 441 ++number_of_non_empty_text_non_password_fields;
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 bool HasAutocompleteAttributeValue(const blink::WebInputElement& element, 740 bool HasAutocompleteAttributeValue(const blink::WebInputElement& element,
737 const char* value_in_lowercase) { 741 const char* value_in_lowercase) {
738 base::string16 autocomplete_attribute( 742 base::string16 autocomplete_attribute(
739 element.getAttribute("autocomplete").utf16()); 743 element.getAttribute("autocomplete").utf16());
740 std::vector<std::string> tokens = LowercaseAndTokenizeAttributeString( 744 std::vector<std::string> tokens = LowercaseAndTokenizeAttributeString(
741 base::UTF16ToUTF8(autocomplete_attribute)); 745 base::UTF16ToUTF8(autocomplete_attribute));
742 746
743 return base::ContainsValue(tokens, value_in_lowercase); 747 return base::ContainsValue(tokens, value_in_lowercase);
744 } 748 }
745 749
750 bool HasCreditCardAutocompleteAttributes(
751 const blink::WebInputElement& element) {
752 std::string autocomplete_value_lowercase = base::ToLowerASCII(
753 base::UTF16ToUTF8(element.getAttribute("autocomplete").utf16()));
754 // All credit cards autocomplete attributes start with "cc-". So if there is a
vabr (Chromium) 2017/03/23 20:04:23 I wonder whether this would be simpler to code wit
dvadym 2017/03/24 09:34:33 Sure it's simpler. I had a dilemma because of this
Roger McFarlane (Chromium) 2017/03/24 15:47:16 You could use a regular expression with case insen
vabr (Chromium) 2017/03/24 19:19:36 The extra object created is a vector of StringPiec
dvadym 2017/03/27 10:51:40 Changed to call of SplitStringPiece, in this funct
755 // credit card autocomplete attribute then |autocomplete_value_lowercase|
756 // should start from "cc-" or have a substring "<whitespace>cc-".
757 for (size_t index = -1;;) {
758 index = autocomplete_value_lowercase.find(kAutocompleteCreditCardPrefix,
759 index + 1);
760 if (index == std::string::npos)
761 break;
762 if (index == 0 ||
763 base::IsAsciiWhitespace(autocomplete_value_lowercase[index - 1]))
764 return true;
765 }
766 return false;
767 }
768
746 } // namespace autofill 769 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698