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

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: Added more tests 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 | « components/autofill/content/renderer/password_autofill_agent.h ('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),
629 sent_request_to_store_(false),
612 binding_(this) { 630 binding_(this) {
613 // PasswordAutofillAgent is guaranteed to outlive |render_frame|. 631 // PasswordAutofillAgent is guaranteed to outlive |render_frame|.
614 render_frame->GetInterfaceRegistry()->AddInterface( 632 render_frame->GetInterfaceRegistry()->AddInterface(
615 base::Bind(&PasswordAutofillAgent::BindRequest, base::Unretained(this))); 633 base::Bind(&PasswordAutofillAgent::BindRequest, base::Unretained(this)));
616 } 634 }
617 635
618 PasswordAutofillAgent::~PasswordAutofillAgent() { 636 PasswordAutofillAgent::~PasswordAutofillAgent() {
619 } 637 }
620 638
621 void PasswordAutofillAgent::BindRequest( 639 void PasswordAutofillAgent::BindRequest(
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 &form_predictions_)); 1129 &form_predictions_));
1112 if (password_form) { 1130 if (password_form) {
1113 if (logger) { 1131 if (logger) {
1114 logger->LogPasswordForm(Logger::STRING_FORM_IS_PASSWORD, 1132 logger->LogPasswordForm(Logger::STRING_FORM_IS_PASSWORD,
1115 *password_form); 1133 *password_form);
1116 } 1134 }
1117 password_forms.push_back(*password_form); 1135 password_forms.push_back(*password_form);
1118 } 1136 }
1119 } 1137 }
1120 1138
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) { 1139 if (only_visible) {
1140 // Send the PasswordFormsRendered message regardless of whether
1141 // |password_forms| is empty. The empty |password_forms| are a possible
1142 // signal to the browser that a pending login attempt succeeded.
1129 blink::WebFrame* main_frame = render_frame()->GetWebFrame()->Top(); 1143 blink::WebFrame* main_frame = render_frame()->GetWebFrame()->Top();
1130 bool did_stop_loading = !main_frame || !main_frame->IsLoading(); 1144 bool did_stop_loading = !main_frame || !main_frame->IsLoading();
1131 GetPasswordManagerDriver()->PasswordFormsRendered(password_forms, 1145 GetPasswordManagerDriver()->PasswordFormsRendered(password_forms,
1132 did_stop_loading); 1146 did_stop_loading);
1133 } else { 1147 } else {
1134 GetPasswordManagerDriver()->PasswordFormsParsed(password_forms); 1148 // If there is a password field, but the list of password forms is empty for
1149 // some reason, add a dummy form to the list. It will cause a request to the
1150 // store. Therefore, saved passwords will be available for filling on click.
1151 if (!sent_request_to_store_ && password_forms.empty() &&
1152 HasPasswordField(*frame)) {
1153 // Set everything that |FormDigest| needs.
1154 password_forms.push_back(PasswordForm());
1155 password_forms.back().scheme = PasswordForm::SCHEME_HTML;
1156 password_forms.back().origin =
1157 form_util::GetCanonicalOriginForDocument(frame->GetDocument());
1158 GURL::Replacements rep;
1159 rep.SetPathStr("");
1160 password_forms.back().signon_realm =
1161 password_forms.back().origin.ReplaceComponents(rep).spec();
1162 sent_request_to_store_ = true;
1163 }
1164 if (!password_forms.empty())
1165 GetPasswordManagerDriver()->PasswordFormsParsed(password_forms);
1135 } 1166 }
1136 } 1167 }
1137 1168
1138 void PasswordAutofillAgent::DidFinishDocumentLoad() { 1169 void PasswordAutofillAgent::DidFinishDocumentLoad() {
1139 // The |frame| contents have been parsed, but not yet rendered. Let the 1170 // 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 1171 // PasswordManager know that forms are loaded, even though we can't yet tell
1141 // whether they're visible. 1172 // whether they're visible.
1142 form_util::ScopedLayoutPreventer layout_preventer; 1173 form_util::ScopedLayoutPreventer layout_preventer;
1143 SendPasswordForms(false); 1174 SendPasswordForms(false);
1144 } 1175 }
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 return CanShowSuggestion(password_info.fill_data, username_string, show_all); 1589 return CanShowSuggestion(password_info.fill_data, username_string, show_all);
1559 } 1590 }
1560 1591
1561 void PasswordAutofillAgent::FrameClosing() { 1592 void PasswordAutofillAgent::FrameClosing() {
1562 for (auto const& iter : web_input_to_password_info_) { 1593 for (auto const& iter : web_input_to_password_info_) {
1563 password_to_username_.erase(iter.second.password_field); 1594 password_to_username_.erase(iter.second.password_field);
1564 } 1595 }
1565 web_input_to_password_info_.clear(); 1596 web_input_to_password_info_.clear();
1566 provisionally_saved_form_.Reset(); 1597 provisionally_saved_form_.Reset();
1567 field_value_and_properties_map_.clear(); 1598 field_value_and_properties_map_.clear();
1599 sent_request_to_store_ = false;
1568 } 1600 }
1569 1601
1570 void PasswordAutofillAgent::ClearPreview( 1602 void PasswordAutofillAgent::ClearPreview(
1571 blink::WebInputElement* username, 1603 blink::WebInputElement* username,
1572 blink::WebInputElement* password) { 1604 blink::WebInputElement* password) {
1573 if (!username->IsNull() && !username->SuggestedValue().IsEmpty()) { 1605 if (!username->IsNull() && !username->SuggestedValue().IsEmpty()) {
1574 username->SetSuggestedValue(blink::WebString()); 1606 username->SetSuggestedValue(blink::WebString());
1575 username->SetAutofilled(was_username_autofilled_); 1607 username->SetAutofilled(was_username_autofilled_);
1576 username->SetSelectionRange(username_query_prefix_.length(), 1608 username->SetSelectionRange(username_query_prefix_.length(),
1577 username->Value().length()); 1609 username->Value().length());
(...skipping 27 matching lines...) Expand all
1605 PasswordAutofillAgent::GetPasswordManagerDriver() { 1637 PasswordAutofillAgent::GetPasswordManagerDriver() {
1606 if (!password_manager_driver_) { 1638 if (!password_manager_driver_) {
1607 render_frame()->GetRemoteInterfaces()->GetInterface( 1639 render_frame()->GetRemoteInterfaces()->GetInterface(
1608 mojo::MakeRequest(&password_manager_driver_)); 1640 mojo::MakeRequest(&password_manager_driver_));
1609 } 1641 }
1610 1642
1611 return password_manager_driver_; 1643 return password_manager_driver_;
1612 } 1644 }
1613 1645
1614 } // namespace autofill 1646 } // namespace autofill
OLDNEW
« 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