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

Side by Side Diff: components/autofill/content/renderer/password_autofill_agent.cc

Issue 962673004: [Autofill/Autocomplete Feature] Substring matching instead of prefix matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses review comments. Created 5 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
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/metrics/field_trial.h" 11 #include "base/metrics/field_trial.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "components/autofill/content/common/autofill_messages.h" 14 #include "components/autofill/content/common/autofill_messages.h"
15 #include "components/autofill/content/renderer/form_autofill_util.h" 15 #include "components/autofill/content/renderer/form_autofill_util.h"
16 #include "components/autofill/content/renderer/password_form_conversion_utils.h" 16 #include "components/autofill/content/renderer/password_form_conversion_utils.h"
17 #include "components/autofill/content/renderer/renderer_save_password_progress_l ogger.h" 17 #include "components/autofill/content/renderer/renderer_save_password_progress_l ogger.h"
18 #include "components/autofill/core/common/autofill_constants.h" 18 #include "components/autofill/core/common/autofill_constants.h"
19 #include "components/autofill/core/common/autofill_switches.h" 19 #include "components/autofill/core/common/autofill_switches.h"
20 #include "components/autofill/core/common/autofill_util.h"
20 #include "components/autofill/core/common/form_field_data.h" 21 #include "components/autofill/core/common/form_field_data.h"
21 #include "components/autofill/core/common/password_form.h" 22 #include "components/autofill/core/common/password_form.h"
22 #include "components/autofill/core/common/password_form_fill_data.h" 23 #include "components/autofill/core/common/password_form_fill_data.h"
23 #include "content/public/renderer/document_state.h" 24 #include "content/public/renderer/document_state.h"
24 #include "content/public/renderer/navigation_state.h" 25 #include "content/public/renderer/navigation_state.h"
25 #include "content/public/renderer/render_frame.h" 26 #include "content/public/renderer/render_frame.h"
26 #include "content/public/renderer/render_view.h" 27 #include "content/public/renderer/render_view.h"
27 #include "third_party/WebKit/public/platform/WebVector.h" 28 #include "third_party/WebKit/public/platform/WebVector.h"
28 #include "third_party/WebKit/public/web/WebAutofillClient.h" 29 #include "third_party/WebKit/public/web/WebAutofillClient.h"
29 #include "third_party/WebKit/public/web/WebDocument.h" 30 #include "third_party/WebKit/public/web/WebDocument.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 230
230 bool IsElementEditable(const blink::WebInputElement& element) { 231 bool IsElementEditable(const blink::WebInputElement& element) {
231 return element.isEnabled() && !element.isReadOnly(); 232 return element.isEnabled() && !element.isReadOnly();
232 } 233 }
233 234
234 bool DoUsernamesMatch(const base::string16& username1, 235 bool DoUsernamesMatch(const base::string16& username1,
235 const base::string16& username2, 236 const base::string16& username2,
236 bool exact_match) { 237 bool exact_match) {
237 if (exact_match) 238 if (exact_match)
238 return username1 == username2; 239 return username1 == username2;
239 return StartsWith(username1, username2, true); 240 return IsContentsPrefixOfSuggestionToken(username1, username2, true) ||
241 StartsWith(username1, username2, true);
240 } 242 }
241 243
242 // Returns |true| if the given element is editable. Otherwise, returns |false|. 244 // Returns |true| if the given element is editable. Otherwise, returns |false|.
243 bool IsElementAutocompletable(const blink::WebInputElement& element) { 245 bool IsElementAutocompletable(const blink::WebInputElement& element) {
244 return IsElementEditable(element); 246 return IsElementEditable(element);
245 } 247 }
246 248
247 // Returns true if the password specified in |form| is a default value. 249 // Returns true if the password specified in |form| is a default value.
248 bool PasswordValueIsDefault(const base::string16& password_element, 250 bool PasswordValueIsDefault(const base::string16& password_element,
249 const base::string16& password_value, 251 const base::string16& password_value,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 // fields. 421 // fields.
420 422
421 // Input matches the username, fill in required values. 423 // Input matches the username, fill in required values.
422 if (!username_element->isNull() && 424 if (!username_element->isNull() &&
423 IsElementAutocompletable(*username_element)) { 425 IsElementAutocompletable(*username_element)) {
424 username_element->setValue(username, true); 426 username_element->setValue(username, true);
425 nonscript_modified_values[*username_element] = username; 427 nonscript_modified_values[*username_element] = username;
426 username_element->setAutofilled(true); 428 username_element->setAutofilled(true);
427 429
428 if (set_selection) { 430 if (set_selection) {
429 username_element->setSelectionRange(current_username.length(), 431 if (IsFeatureSubstringMatchEnabled()) {
430 username.length()); 432 size_t start = 0;
433 size_t end = 0;
434 if (base::string16::npos !=
435 ComputeRange(username, current_username, &start, &end)) {
436 username_element->setSelectionRange(start, end);
437 }
438 } else {
439 username_element->setSelectionRange(current_username.length(),
440 username.length());
441 }
431 } 442 }
432 } else if (current_username != username) { 443 } else if (current_username != username) {
433 // If the username can't be filled and it doesn't match a saved password 444 // If the username can't be filled and it doesn't match a saved password
434 // as is, don't autofill a password. 445 // as is, don't autofill a password.
435 return other_possible_username_selected; 446 return other_possible_username_selected;
436 } 447 }
437 448
438 // Wait to fill in the password until a user gesture occurs. This is to make 449 // Wait to fill in the password until a user gesture occurs. This is to make
439 // sure that we do not fill in the DOM with a password until we believe the 450 // sure that we do not fill in the DOM with a password until we believe the
440 // user is intentionally interacting with the page. 451 // user is intentionally interacting with the page.
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 const blink::WebString& password) { 768 const blink::WebString& password) {
758 blink::WebInputElement username_element; 769 blink::WebInputElement username_element;
759 PasswordInfo* password_info; 770 PasswordInfo* password_info;
760 771
761 if (!FindLoginInfo(node, &username_element, &password_info) || 772 if (!FindLoginInfo(node, &username_element, &password_info) ||
762 !IsElementAutocompletable(username_element) || 773 !IsElementAutocompletable(username_element) ||
763 !IsElementAutocompletable(password_info->password_field)) { 774 !IsElementAutocompletable(password_info->password_field)) {
764 return false; 775 return false;
765 } 776 }
766 777
778 base::string16 current_username = username_element.value();
779 base::string16 suggested_username = username;
767 was_username_autofilled_ = username_element.isAutofilled(); 780 was_username_autofilled_ = username_element.isAutofilled();
768 username_selection_start_ = username_element.selectionStart(); 781 username_selection_start_ = username_element.selectionStart();
769 username_element.setSuggestedValue(username); 782 username_element.setSuggestedValue(username);
770 username_element.setAutofilled(true); 783 username_element.setAutofilled(true);
771 username_element.setSelectionRange( 784
772 username_selection_start_, 785 if (IsFeatureSubstringMatchEnabled()) {
773 username_element.suggestedValue().length()); 786 size_t start = 0;
787 size_t end = 0;
788 if (base::string16::npos !=
789 ComputeRange(suggested_username, current_username, &start, &end)) {
790 username_element.setSelectionRange(start, end);
791 was_username_autofilled_ = start;
792 }
793 } else {
794 username_element.setSelectionRange(
795 username_selection_start_, username_element.suggestedValue().length());
796 }
774 797
775 was_password_autofilled_ = password_info->password_field.isAutofilled(); 798 was_password_autofilled_ = password_info->password_field.isAutofilled();
776 password_info->password_field.setSuggestedValue(password); 799 password_info->password_field.setSuggestedValue(password);
777 password_info->password_field.setAutofilled(true); 800 password_info->password_field.setAutofilled(true);
778 801
779 return true; 802 return true;
780 } 803 }
781 804
782 bool PasswordAutofillAgent::DidClearAutofillSelection( 805 bool PasswordAutofillAgent::DidClearAutofillSelection(
783 const blink::WebNode& node) { 806 const blink::WebNode& node) {
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { 1456 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() {
1434 agent_->DidStopLoading(); 1457 agent_->DidStopLoading();
1435 } 1458 }
1436 1459
1437 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: 1460 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::
1438 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { 1461 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) {
1439 agent_->LegacyDidStartProvisionalLoad(navigated_frame); 1462 agent_->LegacyDidStartProvisionalLoad(navigated_frame);
1440 } 1463 }
1441 1464
1442 } // namespace autofill 1465 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698