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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « chrome/renderer/autofill/password_autofill_agent_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_autofill_agent.h" 5 #include "components/autofill/content/renderer/password_autofill_agent.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 continue; 592 continue;
593 control_element.SetAttribute( 593 control_element.SetAttribute(
594 blink::WebString::FromASCII(kDebugAttributeForFieldSignature), 594 blink::WebString::FromASCII(kDebugAttributeForFieldSignature),
595 blink::WebString::FromUTF8( 595 blink::WebString::FromUTF8(
596 base::Uint64ToString(CalculateFieldSignatureForField(field)))); 596 base::Uint64ToString(CalculateFieldSignatureForField(field))));
597 } 597 }
598 } 598 }
599 } 599 }
600 } 600 }
601 601
602 // Returns true iff there is a password field in |frame|.
603 bool HasPasswordField(const blink::WebLocalFrame& frame) {
604 CR_DEFINE_STATIC_LOCAL(blink::WebString, kPassword, ("password"));
605
606 const blink::WebElementCollection elements = frame.GetDocument().All();
607 for (blink::WebElement element = elements.FirstItem(); !element.IsNull();
608 element = elements.NextItem()) {
609 if (element.IsFormControlElement()) {
610 const blink::WebFormControlElement& control =
611 element.To<blink::WebFormControlElement>();
612 if (control.FormControlType() == kPassword)
613 return true;
614 }
615 }
616 return false;
617 }
618
602 } // namespace 619 } // namespace
603 620
604 //////////////////////////////////////////////////////////////////////////////// 621 ////////////////////////////////////////////////////////////////////////////////
605 // PasswordAutofillAgent, public: 622 // PasswordAutofillAgent, public:
606 623
607 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderFrame* render_frame) 624 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderFrame* render_frame)
608 : content::RenderFrameObserver(render_frame), 625 : content::RenderFrameObserver(render_frame),
609 logging_state_active_(false), 626 logging_state_active_(false),
610 was_username_autofilled_(false), 627 was_username_autofilled_(false),
611 was_password_autofilled_(false), 628 was_password_autofilled_(false),
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 &form_predictions_)); 1128 &form_predictions_));
1112 if (password_form) { 1129 if (password_form) {
1113 if (logger) { 1130 if (logger) {
1114 logger->LogPasswordForm(Logger::STRING_FORM_IS_PASSWORD, 1131 logger->LogPasswordForm(Logger::STRING_FORM_IS_PASSWORD,
1115 *password_form); 1132 *password_form);
1116 } 1133 }
1117 password_forms.push_back(*password_form); 1134 password_forms.push_back(*password_form);
1118 } 1135 }
1119 } 1136 }
1120 1137
1121 if (password_forms.empty() && !only_visible) {
1122 // We need to send the PasswordFormsRendered message regardless of whether
1123 // there are any forms visible, as this is also the code path that triggers
1124 // showing the infobar.
1125 return;
1126 }
1127
1128 if (only_visible) { 1138 if (only_visible) {
1139 // Send the PasswordFormsRendered message regardless of whether
1140 // |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.
1141 // signal to the browser that a pending login attempt succeeded.
1129 blink::WebFrame* main_frame = render_frame()->GetWebFrame()->Top(); 1142 blink::WebFrame* main_frame = render_frame()->GetWebFrame()->Top();
1130 bool did_stop_loading = !main_frame || !main_frame->IsLoading(); 1143 bool did_stop_loading = !main_frame || !main_frame->IsLoading();
1131 GetPasswordManagerDriver()->PasswordFormsRendered(password_forms, 1144 GetPasswordManagerDriver()->PasswordFormsRendered(password_forms,
1132 did_stop_loading); 1145 did_stop_loading);
1133 } else { 1146 } else {
1134 GetPasswordManagerDriver()->PasswordFormsParsed(password_forms); 1147 // If there is a password field, but the list of password forms is empty for
1148 // some reason, add a dummy form to the list. It will cause a request to the
1149 // store. Therefore, saved passwords will be available for filling on click.
1150 if (password_forms.empty() && HasPasswordField(*frame)) {
1151 std::unique_ptr<PasswordForm> password_form(new PasswordForm());
1152 // Set everything that |FormDigest| needs.
1153 password_form->scheme = PasswordForm::SCHEME_HTML;
1154 password_form->origin =
1155 form_util::GetCanonicalOriginForDocument(frame->GetDocument());
1156 GURL::Replacements rep;
1157 rep.SetPathStr("");
1158 password_form->signon_realm =
1159 password_form->origin.ReplaceComponents(rep).spec();
1160 password_forms.push_back(*password_form);
1161 }
1162 if (!password_forms.empty())
1163 GetPasswordManagerDriver()->PasswordFormsParsed(password_forms);
1135 } 1164 }
1136 } 1165 }
1137 1166
1138 void PasswordAutofillAgent::DidFinishDocumentLoad() { 1167 void PasswordAutofillAgent::DidFinishDocumentLoad() {
1139 // The |frame| contents have been parsed, but not yet rendered. Let the 1168 // The |frame| contents have been parsed, but not yet rendered. Let the
1140 // PasswordManager know that forms are loaded, even though we can't yet tell 1169 // PasswordManager know that forms are loaded, even though we can't yet tell
1141 // whether they're visible. 1170 // whether they're visible.
1142 form_util::ScopedLayoutPreventer layout_preventer; 1171 form_util::ScopedLayoutPreventer layout_preventer;
1143 SendPasswordForms(false); 1172 SendPasswordForms(false);
1144 } 1173 }
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 PasswordAutofillAgent::GetPasswordManagerDriver() { 1634 PasswordAutofillAgent::GetPasswordManagerDriver() {
1606 if (!password_manager_driver_) { 1635 if (!password_manager_driver_) {
1607 render_frame()->GetRemoteInterfaces()->GetInterface( 1636 render_frame()->GetRemoteInterfaces()->GetInterface(
1608 mojo::MakeRequest(&password_manager_driver_)); 1637 mojo::MakeRequest(&password_manager_driver_));
1609 } 1638 }
1610 1639
1611 return password_manager_driver_; 1640 return password_manager_driver_;
1612 } 1641 }
1613 1642
1614 } // namespace autofill 1643 } // namespace autofill
OLDNEW
« 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