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

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: Removed suggestions ordering prefix/substring and unittests. Created 5 years, 9 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 IsFeatureSubstringMatchEnabled()
241 ? IsContentsPrefixOfSuggestionToken(username1, username2,
242 CASE_SENSITIVE)
243 : StartsWith(username1, username2, true);
240 } 244 }
241 245
242 // Returns |true| if the given element is editable. Otherwise, returns |false|. 246 // Returns |true| if the given element is editable. Otherwise, returns |false|.
243 bool IsElementAutocompletable(const blink::WebInputElement& element) { 247 bool IsElementAutocompletable(const blink::WebInputElement& element) {
244 return IsElementEditable(element); 248 return IsElementEditable(element);
245 } 249 }
246 250
247 // Returns true if the password specified in |form| is a default value. 251 // Returns true if the password specified in |form| is a default value.
248 bool PasswordValueIsDefault(const base::string16& password_element, 252 bool PasswordValueIsDefault(const base::string16& password_element,
249 const base::string16& password_value, 253 const base::string16& password_value,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 // fields. 423 // fields.
420 424
421 // Input matches the username, fill in required values. 425 // Input matches the username, fill in required values.
422 if (!username_element->isNull() && 426 if (!username_element->isNull() &&
423 IsElementAutocompletable(*username_element)) { 427 IsElementAutocompletable(*username_element)) {
424 username_element->setValue(username, true); 428 username_element->setValue(username, true);
425 nonscript_modified_values[*username_element] = username; 429 nonscript_modified_values[*username_element] = username;
426 username_element->setAutofilled(true); 430 username_element->setAutofilled(true);
427 431
428 if (set_selection) { 432 if (set_selection) {
429 username_element->setSelectionRange(current_username.length(), 433 if (IsFeatureSubstringMatchEnabled()) {
430 username.length()); 434 size_t start = 0;
435 size_t end = 0;
436 if (base::string16::npos !=
437 ComputeRange(username, current_username, &start, &end)) {
438 username_element->setSelectionRange(start, end);
439 }
440 } else {
441 username_element->setSelectionRange(current_username.length(),
442 username.length());
443 }
431 } 444 }
432 } else if (current_username != username) { 445 } else if (current_username != username) {
433 // If the username can't be filled and it doesn't match a saved password 446 // If the username can't be filled and it doesn't match a saved password
434 // as is, don't autofill a password. 447 // as is, don't autofill a password.
435 return other_possible_username_selected; 448 return other_possible_username_selected;
436 } 449 }
437 450
438 // Wait to fill in the password until a user gesture occurs. This is to make 451 // 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 452 // sure that we do not fill in the DOM with a password until we believe the
440 // user is intentionally interacting with the page. 453 // user is intentionally interacting with the page.
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 const blink::WebString& password) { 770 const blink::WebString& password) {
758 blink::WebInputElement username_element; 771 blink::WebInputElement username_element;
759 PasswordInfo* password_info; 772 PasswordInfo* password_info;
760 773
761 if (!FindLoginInfo(node, &username_element, &password_info) || 774 if (!FindLoginInfo(node, &username_element, &password_info) ||
762 !IsElementAutocompletable(username_element) || 775 !IsElementAutocompletable(username_element) ||
763 !IsElementAutocompletable(password_info->password_field)) { 776 !IsElementAutocompletable(password_info->password_field)) {
764 return false; 777 return false;
765 } 778 }
766 779
780 base::string16 current_username = username_element.value();
781 base::string16 suggested_username = username;
767 was_username_autofilled_ = username_element.isAutofilled(); 782 was_username_autofilled_ = username_element.isAutofilled();
768 username_selection_start_ = username_element.selectionStart(); 783 username_selection_start_ = username_element.selectionStart();
769 username_element.setSuggestedValue(username); 784 username_element.setSuggestedValue(username);
770 username_element.setAutofilled(true); 785 username_element.setAutofilled(true);
771 username_element.setSelectionRange( 786
772 username_selection_start_, 787 if (IsFeatureSubstringMatchEnabled()) {
773 username_element.suggestedValue().length()); 788 size_t start = 0;
789 size_t end = 0;
790 if (base::string16::npos !=
791 ComputeRange(suggested_username, current_username, &start, &end)) {
792 username_element.setSelectionRange(start, end);
793 was_username_autofilled_ = start;
794 }
795 } else {
796 username_element.setSelectionRange(
797 username_selection_start_, username_element.suggestedValue().length());
798 }
774 799
775 was_password_autofilled_ = password_info->password_field.isAutofilled(); 800 was_password_autofilled_ = password_info->password_field.isAutofilled();
776 password_info->password_field.setSuggestedValue(password); 801 password_info->password_field.setSuggestedValue(password);
777 password_info->password_field.setAutofilled(true); 802 password_info->password_field.setAutofilled(true);
778 803
779 return true; 804 return true;
780 } 805 }
781 806
782 bool PasswordAutofillAgent::DidClearAutofillSelection( 807 bool PasswordAutofillAgent::DidClearAutofillSelection(
783 const blink::WebNode& node) { 808 const blink::WebNode& node) {
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { 1458 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() {
1434 agent_->DidStopLoading(); 1459 agent_->DidStopLoading();
1435 } 1460 }
1436 1461
1437 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: 1462 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::
1438 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { 1463 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) {
1439 agent_->LegacyDidStartProvisionalLoad(navigated_frame); 1464 agent_->LegacyDidStartProvisionalLoad(navigated_frame);
1440 } 1465 }
1441 1466
1442 } // namespace autofill 1467 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698