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

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

Issue 2814093002: [Password Manager] Send a request to the password store if there is a password field on a page (Closed)
Patch Set: Changes addressed to reviewer's comments Created 3 years, 8 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 | « chrome/renderer/autofill/password_autofill_agent_browsertest.cc ('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 51a16769c8209b2febc1529cdefd4983f43ae6d8..736dc7a21a5073c2b2b8ca170b77b3f33c68d488 100644
--- a/components/autofill/content/renderer/password_autofill_agent.cc
+++ b/components/autofill/content/renderer/password_autofill_agent.cc
@@ -599,6 +599,23 @@ void AnnotateFormsWithSignatures(
}
}
+// Returns true iff there is a password field in |frame|.
+bool HasPasswordField(const blink::WebLocalFrame& frame) {
+ CR_DEFINE_STATIC_LOCAL(blink::WebString, kPassword, ("password"));
+
+ const blink::WebElementCollection elements = frame.GetDocument().All();
+ for (blink::WebElement element = elements.FirstItem(); !element.IsNull();
+ element = elements.NextItem()) {
+ if (element.IsFormControlElement()) {
+ const blink::WebFormControlElement& control =
+ element.To<blink::WebFormControlElement>();
+ if (control.FormControlType() == kPassword)
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace
////////////////////////////////////////////////////////////////////////////////
@@ -1118,20 +1135,32 @@ void PasswordAutofillAgent::SendPasswordForms(bool only_visible) {
}
}
- if (password_forms.empty() && !only_visible) {
- // We need to send the PasswordFormsRendered message regardless of whether
- // there are any forms visible, as this is also the code path that triggers
- // showing the infobar.
- return;
- }
-
if (only_visible) {
+ // Send the PasswordFormsRendered message regardless of whether
+ // |password_forms| is empty. The empty |password_forms| are a possible
vabr (Chromium) 2017/04/13 10:12:58 nit: Please re-flow the comment block to remove un
kolos1 2017/04/13 13:26:06 Done.
+ // signal to the browser that a pending login attempt succeeded.
blink::WebFrame* main_frame = render_frame()->GetWebFrame()->Top();
bool did_stop_loading = !main_frame || !main_frame->IsLoading();
GetPasswordManagerDriver()->PasswordFormsRendered(password_forms,
did_stop_loading);
} else {
- GetPasswordManagerDriver()->PasswordFormsParsed(password_forms);
+ // If there is a password field, but the list of password forms is empty for
+ // some reason, add a dummy form to the list. It will cause a request to the
+ // store. Therefore, saved passwords will be available for filling on click.
+ if (password_forms.empty() && HasPasswordField(*frame)) {
+ std::unique_ptr<PasswordForm> password_form(new PasswordForm());
+ // Set everything that |FormDigest| needs.
+ password_form->scheme = PasswordForm::SCHEME_HTML;
+ password_form->origin =
+ form_util::GetCanonicalOriginForDocument(frame->GetDocument());
+ GURL::Replacements rep;
+ rep.SetPathStr("");
+ password_form->signon_realm =
+ password_form->origin.ReplaceComponents(rep).spec();
+ password_forms.push_back(*password_form);
+ }
+ if (!password_forms.empty())
+ GetPasswordManagerDriver()->PasswordFormsParsed(password_forms);
}
}
« no previous file with comments | « chrome/renderer/autofill/password_autofill_agent_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698