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

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: Added 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 ? HasTokoneStartsWith(username1, username2, true)
Evan Stade 2015/03/24 00:48:26 spelling of this function
Pritam Nikam 2015/03/24 11:39:36 Done.
242 : StartsWith(username1, username2, true);
Evan Stade 2015/03/24 00:48:26 Don't you need to change StartsWith? It seems like
Pritam Nikam 2015/03/24 11:39:36 I my opinion, StartsWith() being used at other pla
240 } 243 }
241 244
242 // Returns |true| if the given element is editable. Otherwise, returns |false|. 245 // Returns |true| if the given element is editable. Otherwise, returns |false|.
243 bool IsElementAutocompletable(const blink::WebInputElement& element) { 246 bool IsElementAutocompletable(const blink::WebInputElement& element) {
244 return IsElementEditable(element); 247 return IsElementEditable(element);
245 } 248 }
246 249
247 // Returns true if the password specified in |form| is a default value. 250 // Returns true if the password specified in |form| is a default value.
248 bool PasswordValueIsDefault(const base::string16& password_element, 251 bool PasswordValueIsDefault(const base::string16& password_element,
249 const base::string16& password_value, 252 const base::string16& password_value,
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 // fields. 422 // fields.
420 423
421 // Input matches the username, fill in required values. 424 // Input matches the username, fill in required values.
422 if (!username_element->isNull() && 425 if (!username_element->isNull() &&
423 IsElementAutocompletable(*username_element)) { 426 IsElementAutocompletable(*username_element)) {
424 username_element->setValue(username, true); 427 username_element->setValue(username, true);
425 nonscript_modified_values[*username_element] = username; 428 nonscript_modified_values[*username_element] = username;
426 username_element->setAutofilled(true); 429 username_element->setAutofilled(true);
427 430
428 if (set_selection) { 431 if (set_selection) {
429 username_element->setSelectionRange(current_username.length(), 432 if (IsFeatureSubStringMatchEnabled()) {
430 username.length()); 433 size_t start = 0, 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 =
779 static_cast<base::string16>(username_element.value());
780 base::string16 suggested_username = static_cast<base::string16>(username);
767 was_username_autofilled_ = username_element.isAutofilled(); 781 was_username_autofilled_ = username_element.isAutofilled();
768 username_selection_start_ = username_element.selectionStart(); 782 username_selection_start_ = username_element.selectionStart();
769 username_element.setSuggestedValue(username); 783 username_element.setSuggestedValue(username);
770 username_element.setAutofilled(true); 784 username_element.setAutofilled(true);
771 username_element.setSelectionRange( 785
772 username_selection_start_, 786 if (IsFeatureSubStringMatchEnabled()) {
773 username_element.suggestedValue().length()); 787 size_t start = 0, 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 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 username.selectionEnd() != static_cast<int>(username.value().length())) { 1313 username.selectionEnd() != static_cast<int>(username.value().length())) {
1291 return; 1314 return;
1292 } 1315 }
1293 1316
1294 // Show the popup with the list of available usernames. 1317 // Show the popup with the list of available usernames.
1295 ShowSuggestionPopup(fill_data, username, false, false); 1318 ShowSuggestionPopup(fill_data, username, false, false);
1296 1319
1297 #if !defined(OS_ANDROID) 1320 #if !defined(OS_ANDROID)
1298 // Fill the user and password field with the most relevant match. Android 1321 // Fill the user and password field with the most relevant match. Android
1299 // only fills in the fields after the user clicks on the suggestion popup. 1322 // only fills in the fields after the user clicks on the suggestion popup.
1300 if (FillUserNameAndPassword( 1323 if (!IsFeatureSubStringMatchEnabled() &&
1324 FillUserNameAndPassword(
1301 &username, 1325 &username,
1302 &password, 1326 &password,
1303 fill_data, 1327 fill_data,
1304 false /* exact_username_match */, 1328 false /* exact_username_match */,
1305 true /* set selection */, 1329 true /* set selection */,
1306 nonscript_modified_values_, 1330 nonscript_modified_values_,
1307 base::Bind(&PasswordValueGatekeeper::RegisterElement, 1331 base::Bind(&PasswordValueGatekeeper::RegisterElement,
1308 base::Unretained(&gatekeeper_)))) { 1332 base::Unretained(&gatekeeper_)))) {
1309 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SELECTED; 1333 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SELECTED;
1310 } 1334 }
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { 1412 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() {
1389 agent_->DidStopLoading(); 1413 agent_->DidStopLoading();
1390 } 1414 }
1391 1415
1392 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: 1416 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::
1393 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { 1417 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) {
1394 agent_->LegacyDidStartProvisionalLoad(navigated_frame); 1418 agent_->LegacyDidStartProvisionalLoad(navigated_frame);
1395 } 1419 }
1396 1420
1397 } // namespace autofill 1421 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698