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

Unified 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: Do not create string in HasAutocompleteAttributeValue 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/content/renderer/password_form_conversion_utils.cc
diff --git a/components/autofill/content/renderer/password_form_conversion_utils.cc b/components/autofill/content/renderer/password_form_conversion_utils.cc
index e02d83dbb53d099739cbb77a85eb39c9b49addfa..f128e0b4647cc6673a62357f25d573eeef1842ce 100644
--- a/components/autofill/content/renderer/password_form_conversion_utils.cc
+++ b/components/autofill/content/renderer/password_form_conversion_utils.cc
@@ -15,6 +15,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "base/strings/string16.h"
+#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/content/renderer/form_autofill_util.h"
@@ -93,6 +94,7 @@ const char kLoginAndSignupRegex[] =
const char kAutocompleteUsername[] = "username";
const char kAutocompleteCurrentPassword[] = "current-password";
const char kAutocompleteNewPassword[] = "new-password";
+const char kAutocompleteCreditCardPrefix[] = "cc-";
re2::RE2* CreateMatcher(void* instance, const char* pattern) {
re2::RE2::Options options;
@@ -425,6 +427,9 @@ bool GetPasswordForm(
if (!input_element || !input_element->isEnabled())
continue;
+ if (HasCreditCardAutocompleteAttributes(*input_element))
+ continue;
+
bool element_is_invisible = !form_util::IsWebNodeVisible(*input_element);
if (input_element->isTextField()) {
if (input_element->isPasswordField()) {
@@ -735,12 +740,30 @@ std::unique_ptr<PasswordForm> CreatePasswordFormFromUnownedInputElements(
bool HasAutocompleteAttributeValue(const blink::WebInputElement& element,
const char* value_in_lowercase) {
- base::string16 autocomplete_attribute(
- element.getAttribute("autocomplete").utf16());
- std::vector<std::string> tokens = LowercaseAndTokenizeAttributeString(
- base::UTF16ToUTF8(autocomplete_attribute));
+ std::string autocomplete_value_lowercase = base::ToLowerASCII(
+ base::UTF16ToUTF8(element.getAttribute("autocomplete").utf16()));
+
+ std::vector<base::StringPiece> tokens = base::SplitStringPiece(
+ autocomplete_value_lowercase, base::kWhitespaceASCII,
+ base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
return base::ContainsValue(tokens, value_in_lowercase);
}
+bool HasCreditCardAutocompleteAttributes(
+ const blink::WebInputElement& element) {
+ std::string autocomplete_value_lowercase = base::ToLowerASCII(
+ base::UTF16ToUTF8(element.getAttribute("autocomplete").utf16()));
+
+ for (const auto& token : base::SplitStringPiece(
Roger McFarlane (Chromium) 2017/03/27 19:06:28 Another, IMO better, alternative would be to just
vabr (Chromium) 2017/03/27 20:20:03 It is indeed O(n) because the length of " cc-" is
dvadym 2017/03/28 08:33:08 When using regexp, there are 2 times: creating a r
+ autocomplete_value_lowercase, base::kWhitespaceASCII,
+ base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) {
+ if (base::StartsWith(token, kAutocompleteCreditCardPrefix,
+ base::CompareCase::SENSITIVE)) {
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698