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

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: Modified to resolve bot breakages. Created 5 years, 5 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/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/field_trial.h" 12 #include "base/metrics/field_trial.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "components/autofill/content/common/autofill_messages.h" 15 #include "components/autofill/content/common/autofill_messages.h"
16 #include "components/autofill/content/renderer/form_autofill_util.h" 16 #include "components/autofill/content/renderer/form_autofill_util.h"
17 #include "components/autofill/content/renderer/password_form_conversion_utils.h" 17 #include "components/autofill/content/renderer/password_form_conversion_utils.h"
18 #include "components/autofill/content/renderer/renderer_save_password_progress_l ogger.h" 18 #include "components/autofill/content/renderer/renderer_save_password_progress_l ogger.h"
19 #include "components/autofill/core/common/autofill_constants.h" 19 #include "components/autofill/core/common/autofill_constants.h"
20 #include "components/autofill/core/common/autofill_switches.h" 20 #include "components/autofill/core/common/autofill_switches.h"
21 #include "components/autofill/core/common/autofill_util.h"
21 #include "components/autofill/core/common/form_field_data.h" 22 #include "components/autofill/core/common/form_field_data.h"
22 #include "components/autofill/core/common/password_form.h" 23 #include "components/autofill/core/common/password_form.h"
23 #include "components/autofill/core/common/password_form_fill_data.h" 24 #include "components/autofill/core/common/password_form_fill_data.h"
24 #include "content/public/renderer/document_state.h" 25 #include "content/public/renderer/document_state.h"
25 #include "content/public/renderer/navigation_state.h" 26 #include "content/public/renderer/navigation_state.h"
26 #include "content/public/renderer/render_frame.h" 27 #include "content/public/renderer/render_frame.h"
27 #include "content/public/renderer/render_view.h" 28 #include "content/public/renderer/render_view.h"
28 #include "third_party/WebKit/public/platform/WebVector.h" 29 #include "third_party/WebKit/public/platform/WebVector.h"
29 #include "third_party/WebKit/public/web/WebAutofillClient.h" 30 #include "third_party/WebKit/public/web/WebAutofillClient.h"
30 #include "third_party/WebKit/public/web/WebDocument.h" 31 #include "third_party/WebKit/public/web/WebDocument.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 220
220 bool IsElementEditable(const blink::WebInputElement& element) { 221 bool IsElementEditable(const blink::WebInputElement& element) {
221 return element.isEnabled() && !element.isReadOnly(); 222 return element.isEnabled() && !element.isReadOnly();
222 } 223 }
223 224
224 bool DoUsernamesMatch(const base::string16& username1, 225 bool DoUsernamesMatch(const base::string16& username1,
225 const base::string16& username2, 226 const base::string16& username2,
226 bool exact_match) { 227 bool exact_match) {
227 if (exact_match) 228 if (exact_match)
228 return username1 == username2; 229 return username1 == username2;
229 return base::StartsWith(username1, username2, base::CompareCase::SENSITIVE); 230 return base::StartsWith(username1, username2, base::CompareCase::SENSITIVE) ||
vabr (Chromium) 2015/07/09 06:17:51 I understand that the StartsWith call is there in
Pritam Nikam 2015/07/10 16:58:45 For autofill & CC suggestions we are using base::S
vabr (Chromium) 2015/07/13 14:04:25 I don't understand what you mean. FieldIsSuggestio
Pritam Nikam 2015/07/14 10:30:07 Done.
231 ContainsTokenThatStartsWith(username1, username2, true);
230 } 232 }
231 233
232 // Returns |true| if the given element is editable. Otherwise, returns |false|. 234 // Returns |true| if the given element is editable. Otherwise, returns |false|.
233 bool IsElementAutocompletable(const blink::WebInputElement& element) { 235 bool IsElementAutocompletable(const blink::WebInputElement& element) {
234 return IsElementEditable(element); 236 return IsElementEditable(element);
235 } 237 }
236 238
237 // Returns true if the password specified in |form| is a default value. 239 // Returns true if the password specified in |form| is a default value.
238 bool PasswordValueIsDefault(const base::string16& password_element, 240 bool PasswordValueIsDefault(const base::string16& password_element,
239 const base::string16& password_value, 241 const base::string16& password_value,
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 413 }
412 if (password.empty()) 414 if (password.empty())
413 return other_possible_username_selected; // No match was found. 415 return other_possible_username_selected; // No match was found.
414 416
415 // TODO(tkent): Check maxlength and pattern for both username and password 417 // TODO(tkent): Check maxlength and pattern for both username and password
416 // fields. 418 // fields.
417 419
418 // Input matches the username, fill in required values. 420 // Input matches the username, fill in required values.
419 if (!username_element->isNull() && 421 if (!username_element->isNull() &&
420 IsElementAutocompletable(*username_element)) { 422 IsElementAutocompletable(*username_element)) {
421 username_element->setValue(username, true); 423 username_element->setValue(username, true);
vabr (Chromium) 2015/07/09 08:27:50 Please add: // TODO(vabr): Why not setSuggestedVal
Pritam Nikam 2015/07/10 16:58:46 Done.
422 nonscript_modified_values[*username_element] = username; 424 nonscript_modified_values[*username_element] = username;
423 username_element->setAutofilled(true); 425 username_element->setAutofilled(true);
424 426 if (set_selection)
425 if (set_selection) { 427 PreviewSuggestion(username, current_username, username_element);
426 username_element->setSelectionRange(current_username.length(),
427 username.length());
428 }
429 } else if (current_username != username) { 428 } else if (current_username != username) {
430 // If the username can't be filled and it doesn't match a saved password 429 // If the username can't be filled and it doesn't match a saved password
431 // as is, don't autofill a password. 430 // as is, don't autofill a password.
432 return other_possible_username_selected; 431 return other_possible_username_selected;
433 } 432 }
434 433
435 // Wait to fill in the password until a user gesture occurs. This is to make 434 // Wait to fill in the password until a user gesture occurs. This is to make
436 // sure that we do not fill in the DOM with a password until we believe the 435 // sure that we do not fill in the DOM with a password until we believe the
437 // user is intentionally interacting with the page. 436 // user is intentionally interacting with the page.
438 password_element->setSuggestedValue(password); 437 password_element->setSuggestedValue(password);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 //////////////////////////////////////////////////////////////////////////////// 564 ////////////////////////////////////////////////////////////////////////////////
566 // PasswordAutofillAgent, public: 565 // PasswordAutofillAgent, public:
567 566
568 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderFrame* render_frame) 567 PasswordAutofillAgent::PasswordAutofillAgent(content::RenderFrame* render_frame)
569 : content::RenderFrameObserver(render_frame), 568 : content::RenderFrameObserver(render_frame),
570 legacy_(render_frame->GetRenderView(), this), 569 legacy_(render_frame->GetRenderView(), this),
571 usernames_usage_(NOTHING_TO_AUTOFILL), 570 usernames_usage_(NOTHING_TO_AUTOFILL),
572 logging_state_active_(false), 571 logging_state_active_(false),
573 was_username_autofilled_(false), 572 was_username_autofilled_(false),
574 was_password_autofilled_(false), 573 was_password_autofilled_(false),
575 username_selection_start_(0),
576 did_stop_loading_(false), 574 did_stop_loading_(false),
577 weak_ptr_factory_(this) { 575 weak_ptr_factory_(this) {
578 Send(new AutofillHostMsg_PasswordAutofillAgentConstructed(routing_id())); 576 Send(new AutofillHostMsg_PasswordAutofillAgentConstructed(routing_id()));
579 } 577 }
580 578
581 PasswordAutofillAgent::~PasswordAutofillAgent() { 579 PasswordAutofillAgent::~PasswordAutofillAgent() {
582 } 580 }
583 581
584 PasswordAutofillAgent::PasswordValueGatekeeper::PasswordValueGatekeeper() 582 PasswordAutofillAgent::PasswordValueGatekeeper::PasswordValueGatekeeper()
585 : was_user_gesture_seen_(false) { 583 : was_user_gesture_seen_(false) {
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 const blink::WebString& password) { 790 const blink::WebString& password) {
793 blink::WebInputElement username_element; 791 blink::WebInputElement username_element;
794 PasswordInfo* password_info; 792 PasswordInfo* password_info;
795 793
796 if (!FindLoginInfo(node, &username_element, &password_info) || 794 if (!FindLoginInfo(node, &username_element, &password_info) ||
797 !IsElementAutocompletable(username_element) || 795 !IsElementAutocompletable(username_element) ||
798 !IsElementAutocompletable(password_info->password_field)) { 796 !IsElementAutocompletable(password_info->password_field)) {
799 return false; 797 return false;
800 } 798 }
801 799
800 if (username_query_prefix_.empty())
801 username_query_prefix_ = username_element.value();
802
802 was_username_autofilled_ = username_element.isAutofilled(); 803 was_username_autofilled_ = username_element.isAutofilled();
803 username_selection_start_ = username_element.selectionStart();
804 username_element.setSuggestedValue(username); 804 username_element.setSuggestedValue(username);
805 username_element.setAutofilled(true); 805 username_element.setAutofilled(true);
806 username_element.setSelectionRange( 806 ::autofill::PreviewSuggestion(username_element.suggestedValue(),
807 username_selection_start_, 807 username_query_prefix_, &username_element);
808 username_element.suggestedValue().length());
809
810 was_password_autofilled_ = password_info->password_field.isAutofilled(); 808 was_password_autofilled_ = password_info->password_field.isAutofilled();
811 password_info->password_field.setSuggestedValue(password); 809 password_info->password_field.setSuggestedValue(password);
812 password_info->password_field.setAutofilled(true); 810 password_info->password_field.setAutofilled(true);
813 811
814 return true; 812 return true;
815 } 813 }
816 814
817 bool PasswordAutofillAgent::DidClearAutofillSelection( 815 bool PasswordAutofillAgent::DidClearAutofillSelection(
818 const blink::WebNode& node) { 816 const blink::WebNode& node) {
819 blink::WebInputElement username_element; 817 blink::WebInputElement username_element;
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 options |= SHOW_ALL; 1360 options |= SHOW_ALL;
1363 if (show_on_password_field) 1361 if (show_on_password_field)
1364 options |= IS_PASSWORD_FIELD; 1362 options |= IS_PASSWORD_FIELD;
1365 base::string16 username_string( 1363 base::string16 username_string(
1366 username.isNull() ? base::string16() 1364 username.isNull() ? base::string16()
1367 : static_cast<base::string16>(user_input.value())); 1365 : static_cast<base::string16>(user_input.value()));
1368 Send(new AutofillHostMsg_ShowPasswordSuggestions( 1366 Send(new AutofillHostMsg_ShowPasswordSuggestions(
1369 routing_id(), key_it->second, field.text_direction, username_string, 1367 routing_id(), key_it->second, field.text_direction, username_string,
1370 options, bounding_box_scaled)); 1368 options, bounding_box_scaled));
1371 1369
1370 username_query_prefix_ = username_string;
1372 bool suggestions_present = false; 1371 bool suggestions_present = false;
1373 if (GetSuggestionsStats(fill_data, username_string, show_all, 1372 if (GetSuggestionsStats(fill_data, username_string, show_all,
1374 &suggestions_present)) { 1373 &suggestions_present)) {
1375 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN; 1374 usernames_usage_ = OTHER_POSSIBLE_USERNAME_SHOWN;
1376 } 1375 }
1377 return suggestions_present; 1376 return suggestions_present;
1378 } 1377 }
1379 1378
1380 void PasswordAutofillAgent::PerformInlineAutocomplete( 1379 void PasswordAutofillAgent::PerformInlineAutocomplete(
1381 const blink::WebInputElement& username_input, 1380 const blink::WebInputElement& username_input,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 return FindPasswordInfoForElement(*found_input, &username_element, 1438 return FindPasswordInfoForElement(*found_input, &username_element,
1440 found_password); 1439 found_password);
1441 } 1440 }
1442 1441
1443 void PasswordAutofillAgent::ClearPreview( 1442 void PasswordAutofillAgent::ClearPreview(
1444 blink::WebInputElement* username, 1443 blink::WebInputElement* username,
1445 blink::WebInputElement* password) { 1444 blink::WebInputElement* password) {
1446 if (!username->suggestedValue().isEmpty()) { 1445 if (!username->suggestedValue().isEmpty()) {
1447 username->setSuggestedValue(blink::WebString()); 1446 username->setSuggestedValue(blink::WebString());
1448 username->setAutofilled(was_username_autofilled_); 1447 username->setAutofilled(was_username_autofilled_);
1449 username->setSelectionRange(username_selection_start_, 1448 username->setSelectionRange(username_query_prefix_.length(),
1450 username->value().length()); 1449 username->value().length());
1451 } 1450 }
1452 if (!password->suggestedValue().isEmpty()) { 1451 if (!password->suggestedValue().isEmpty()) {
1453 password->setSuggestedValue(blink::WebString()); 1452 password->setSuggestedValue(blink::WebString());
1454 password->setAutofilled(was_password_autofilled_); 1453 password->setAutofilled(was_password_autofilled_);
1455 } 1454 }
1456 } 1455 }
1457 1456
1458 void PasswordAutofillAgent::ProvisionallySavePassword( 1457 void PasswordAutofillAgent::ProvisionallySavePassword(
1459 const blink::WebFormElement& form, 1458 const blink::WebFormElement& form,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1498 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() { 1497 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::DidStopLoading() {
1499 agent_->DidStopLoading(); 1498 agent_->DidStopLoading();
1500 } 1499 }
1501 1500
1502 void PasswordAutofillAgent::LegacyPasswordAutofillAgent:: 1501 void PasswordAutofillAgent::LegacyPasswordAutofillAgent::
1503 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) { 1502 DidStartProvisionalLoad(blink::WebLocalFrame* navigated_frame) {
1504 agent_->LegacyDidStartProvisionalLoad(navigated_frame); 1503 agent_->LegacyDidStartProvisionalLoad(navigated_frame);
1505 } 1504 }
1506 1505
1507 } // namespace autofill 1506 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698