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

Unified Diff: components/autofill/content/renderer/password_autofill_agent.cc

Issue 2682473002: Show Login Not Secure on username field even without Autocomplete attribute (Closed)
Patch Set: Correct ordering of private fields Created 3 years, 10 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
« no previous file with comments | « components/autofill/content/renderer/password_autofill_agent.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/content/renderer/password_autofill_agent.cc
diff --git a/components/autofill/content/renderer/password_autofill_agent.cc b/components/autofill/content/renderer/password_autofill_agent.cc
index 8eabb52bcaa7ec1136b2010ec8199db6179572d0..aee3f94116bd88b2d321da9d06828be675d15112 100644
--- a/components/autofill/content/renderer/password_autofill_agent.cc
+++ b/components/autofill/content/renderer/password_autofill_agent.cc
@@ -837,6 +837,46 @@ bool PasswordAutofillAgent::FindPasswordInfoForElement(
return true;
}
+bool PasswordAutofillAgent::ShouldShowNotSecureWarning(
+ const blink::WebInputElement& element) {
+ // Do not show a warning if the feature is disabled or the context is secure.
+ if (!security_state::IsHttpWarningInFormEnabled() ||
+ content::IsOriginSecure(
+ url::Origin(render_frame()->GetWebFrame()->top()->getSecurityOrigin())
+ .GetURL()))
+ return false;
+
+ // Show the warning on all Password inputs.
+ // Note: A site may use a Password field to collect a CVV or a Credit Card
+ // number, but showing a slightly misleading warning here is better than
+ // showing no warning at all.
+ if (element.isPasswordField())
+ return true;
+
+ // If a field declares itself a username input, show the warning.
+ if (HasAutocompleteAttributeValue(element, "username"))
+ return true;
+
+ // Otherwise, analyze the form and return true if this input element seems
+ // to be the username field.
+ std::unique_ptr<PasswordForm> password_form;
+ if (element.form().isNull()) {
+ blink::WebFrame* const element_frame = element.document().frame();
+ if (!element_frame)
+ return false;
+
+ password_form = CreatePasswordFormFromUnownedInputElements(
+ *element_frame, &field_value_and_properties_map_, &form_predictions_);
+ } else {
+ password_form = CreatePasswordFormFromWebForm(
+ element.form(), &field_value_and_properties_map_, &form_predictions_);
+ }
+
+ if (!password_form)
+ return false;
+ return (password_form->username_element == element.nameForAutofill().utf16());
+}
+
bool PasswordAutofillAgent::ShowSuggestions(
const blink::WebInputElement& element,
bool show_all,
@@ -847,15 +887,7 @@ bool PasswordAutofillAgent::ShowSuggestions(
if (!FindPasswordInfoForElement(element, &username_element, &password_element,
&password_info)) {
- // If we don't have a password stored, but the form is non-secure, warn
- // the user about the non-secure form.
- if ((element.isPasswordField() ||
- HasAutocompleteAttributeValue(element, "username")) &&
- security_state::IsHttpWarningInFormEnabled() &&
- !content::IsOriginSecure(
- url::Origin(
- render_frame()->GetWebFrame()->top()->getSecurityOrigin())
- .GetURL())) {
+ if (ShouldShowNotSecureWarning(element)) {
autofill_agent_->ShowNotSecureWarning(element);
return true;
}
« no previous file with comments | « components/autofill/content/renderer/password_autofill_agent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698