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); |
} |
} |